From 57d03908827443fd7f2eb40e1c84b3e0ac7dffee Mon Sep 17 00:00:00 2001 From: rappenze Date: Fri, 29 Apr 2022 21:39:45 +0200 Subject: [PATCH] Improve energy meter support of fibaro sensor (#71072) --- homeassistant/components/fibaro/sensor.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/fibaro/sensor.py b/homeassistant/components/fibaro/sensor.py index bd80a9d018193..acaa97ee2a25c 100644 --- a/homeassistant/components/fibaro/sensor.py +++ b/homeassistant/components/fibaro/sensor.py @@ -33,27 +33,43 @@ None, None, SensorDeviceClass.TEMPERATURE, + SensorStateClass.MEASUREMENT, ], "com.fibaro.smokeSensor": [ "Smoke", CONCENTRATION_PARTS_PER_MILLION, "mdi:fire", None, + None, ], "CO2": [ "CO2", CONCENTRATION_PARTS_PER_MILLION, None, - None, SensorDeviceClass.CO2, + SensorStateClass.MEASUREMENT, ], "com.fibaro.humiditySensor": [ "Humidity", PERCENTAGE, None, SensorDeviceClass.HUMIDITY, + SensorStateClass.MEASUREMENT, + ], + "com.fibaro.lightSensor": [ + "Light", + LIGHT_LUX, + None, + SensorDeviceClass.ILLUMINANCE, + SensorStateClass.MEASUREMENT, + ], + "com.fibaro.energyMeter": [ + "Energy", + ENERGY_KILO_WATT_HOUR, + None, + SensorDeviceClass.ENERGY, + SensorStateClass.TOTAL_INCREASING, ], - "com.fibaro.lightSensor": ["Light", LIGHT_LUX, None, SensorDeviceClass.ILLUMINANCE], } @@ -66,7 +82,7 @@ async def async_setup_entry( entities: list[SensorEntity] = [] for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][Platform.SENSOR]: entities.append(FibaroSensor(device)) - for platform in (Platform.COVER, Platform.LIGHT, Platform.SWITCH): + for platform in (Platform.COVER, Platform.LIGHT, Platform.SENSOR, Platform.SWITCH): for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][platform]: if "energy" in device.interfaces: entities.append(FibaroEnergySensor(device)) @@ -89,6 +105,7 @@ def __init__(self, fibaro_device): self._unit = SENSOR_TYPES[fibaro_device.type][1] self._icon = SENSOR_TYPES[fibaro_device.type][2] self._device_class = SENSOR_TYPES[fibaro_device.type][3] + self._attr_state_class = SENSOR_TYPES[fibaro_device.type][4] else: self._unit = None self._icon = None