Add Measurement StateClass to HomematicIP Cloud Wind and Rain Sensor (#129724)

Add Meassurement StateClass to Wind and Rain Sensor
This commit is contained in:
hahn-th 2024-11-03 21:07:59 +01:00 committed by GitHub
parent 144d5ff0cc
commit 0cfd8032c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -420,6 +420,7 @@ class HomematicipWindspeedSensor(HomematicipGenericEntity, SensorEntity):
_attr_device_class = SensorDeviceClass.WIND_SPEED _attr_device_class = SensorDeviceClass.WIND_SPEED
_attr_native_unit_of_measurement = UnitOfSpeed.KILOMETERS_PER_HOUR _attr_native_unit_of_measurement = UnitOfSpeed.KILOMETERS_PER_HOUR
_attr_state_class = SensorStateClass.MEASUREMENT
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the windspeed sensor.""" """Initialize the windspeed sensor."""
@ -451,6 +452,7 @@ class HomematicipTodayRainSensor(HomematicipGenericEntity, SensorEntity):
_attr_device_class = SensorDeviceClass.PRECIPITATION _attr_device_class = SensorDeviceClass.PRECIPITATION
_attr_native_unit_of_measurement = UnitOfPrecipitationDepth.MILLIMETERS _attr_native_unit_of_measurement = UnitOfPrecipitationDepth.MILLIMETERS
_attr_state_class = SensorStateClass.MEASUREMENT
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the device.""" """Initialize the device."""

View file

@ -23,7 +23,11 @@ from homeassistant.components.homematicip_cloud.sensor import (
ATTR_WIND_DIRECTION, ATTR_WIND_DIRECTION,
ATTR_WIND_DIRECTION_VARIATION, ATTR_WIND_DIRECTION_VARIATION,
) )
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.sensor import (
ATTR_STATE_CLASS,
DOMAIN as SENSOR_DOMAIN,
SensorStateClass,
)
from homeassistant.const import ( from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT, ATTR_UNIT_OF_MEASUREMENT,
LIGHT_LUX, LIGHT_LUX,
@ -362,6 +366,7 @@ async def test_hmip_windspeed_sensor(
assert ( assert (
ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfSpeed.KILOMETERS_PER_HOUR ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfSpeed.KILOMETERS_PER_HOUR
) )
assert ha_state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
await async_manipulate_test_data(hass, hmip_device, "windSpeed", 9.4) await async_manipulate_test_data(hass, hmip_device, "windSpeed", 9.4)
ha_state = hass.states.get(entity_id) ha_state = hass.states.get(entity_id)
assert ha_state.state == "9.4" assert ha_state.state == "9.4"
@ -411,6 +416,7 @@ async def test_hmip_today_rain_sensor(
assert ha_state.state == "3.9" assert ha_state.state == "3.9"
assert ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfLength.MILLIMETERS assert ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfLength.MILLIMETERS
assert ha_state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
await async_manipulate_test_data(hass, hmip_device, "todayRainCounter", 14.2) await async_manipulate_test_data(hass, hmip_device, "todayRainCounter", 14.2)
ha_state = hass.states.get(entity_id) ha_state = hass.states.get(entity_id)
assert ha_state.state == "14.2" assert ha_state.state == "14.2"