diff --git a/custom_components/daikin_residential_altherma/sensor.py b/custom_components/daikin_residential_altherma/sensor.py index 05a7f8c9..97a46f5e 100644 --- a/custom_components/daikin_residential_altherma/sensor.py +++ b/custom_components/daikin_residential_altherma/sensor.py @@ -122,8 +122,6 @@ def __init__(self, device: Appliance, embedded_id, management_point_type, operat self._attr_name = f"{mpt} {operation_mode.capitalize()} {periodName} Energy Consumption" self._attr_unique_id = f"{self._device.getId()}_{self._management_point_type}_{self._operation_mode}_{self._period}" self._attr_entity_category = None - self._attr_state_class = STATE_CLASS_TOTAL_INCREASING - self._attr_device_class = DEVICE_CLASS_ENERGY self._attr_icon = icon self._attr_has_entity_name = True _LOGGER.info("Device '%s' '%s' supports sensor '%s'", self._embedded_id, device.name, self._attr_name) @@ -172,6 +170,14 @@ def device_info(self): def unit_of_measurement(self): return ENERGY_KILO_WATT_HOUR + @property + def state_class(self): + return STATE_CLASS_TOTAL_INCREASING + + @property + def device_class(self): + return DEVICE_CLASS_ENERGY + async def async_update(self): """Retrieve latest state.""" await self._device.api.async_update() @@ -186,16 +192,18 @@ def __init__(self, device: Appliance, embedded_id, management_point_type, sub_ty self._sub_type = sub_type self._value = value self._unit_of_measurement = None + self._device_class = None + self._state_class = None self._attr_has_entity_name = True sensor_settings = VALUE_SENSOR_MAPPING.get(value) if sensor_settings is None: _LOGGER.info("No mapping of value '%s' to HA settings, consider adding it to VALUE_SENSOR_MAPPING", value); else: self._attr_icon = sensor_settings[CONF_ICON] - self._attr_device_class = sensor_settings[CONF_DEVICE_CLASS] + self._device_class = sensor_settings[CONF_DEVICE_CLASS] self._unit_of_measurement = sensor_settings[CONF_UNIT_OF_MEASUREMENT] self._attr_entity_registry_enabled_default = sensor_settings[ENABLED_DEFAULT] - self._attr_state_class = sensor_settings[CONF_STATE_CLASS] + self._state_class = sensor_settings[CONF_STATE_CLASS] self._attr_entity_category = sensor_settings[ENTITY_CATEGORY] mpt = management_point_type[0].upper() + management_point_type[1:] myname = value[0].upper() + value[1:] @@ -229,6 +237,14 @@ def available(self): def unit_of_measurement(self): return self._unit_of_measurement + @property + def state_class(self): + return self._state_class + + @property + def device_class(self): + return self._device_class + @property def device_info(self): """Return a device description for device registry."""