diff --git a/custom_components/daikin_residential/const.py b/custom_components/daikin_residential/const.py index 72d8fc4..094ad1a 100644 --- a/custom_components/daikin_residential/const.py +++ b/custom_components/daikin_residential/const.py @@ -8,6 +8,7 @@ CONF_TYPE, CONF_UNIT_OF_MEASUREMENT, DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_ENERGY, ENERGY_KILO_WATT_HOUR, TEMP_CELSIUS, ) @@ -126,12 +127,14 @@ CONF_NAME: "Cool Energy Consumption", CONF_TYPE: SENSOR_TYPE_ENERGY, CONF_ICON: "mdi:snowflake", + CONF_DEVICE_CLASS: DEVICE_CLASS_ENERGY, CONF_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR, }, ATTR_HEAT_ENERGY: { CONF_NAME: "Heat Energy Consumption", CONF_TYPE: SENSOR_TYPE_ENERGY, CONF_ICON: "mdi:fire", + CONF_DEVICE_CLASS: DEVICE_CLASS_ENERGY, CONF_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR, }, } diff --git a/custom_components/daikin_residential/sensor.py b/custom_components/daikin_residential/sensor.py index b679a6d..beae5ae 100644 --- a/custom_components/daikin_residential/sensor.py +++ b/custom_components/daikin_residential/sensor.py @@ -6,7 +6,11 @@ CONF_TYPE, CONF_UNIT_OF_MEASUREMENT, ) -from homeassistant.helpers.entity import Entity +from homeassistant.components.sensor import ( + SensorEntity, + STATE_CLASS_MEASUREMENT, + STATE_CLASS_TOTAL_INCREASING, +) from .daikin_base import Appliance @@ -53,7 +57,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(sensors) -class DaikinSensor(Entity): +class DaikinSensor(SensorEntity): """Representation of a Sensor.""" @staticmethod @@ -62,8 +66,8 @@ def factory(device: Appliance, monitored_state: str, period=""): cls = { SENSOR_TYPE_TEMPERATURE: DaikinClimateSensor, SENSOR_TYPE_HUMIDITY: DaikinClimateSensor, - SENSOR_TYPE_POWER: DaikinPowerSensor, - SENSOR_TYPE_ENERGY: DaikinPowerSensor, + SENSOR_TYPE_POWER: DaikinEnergySensor, + SENSOR_TYPE_ENERGY: DaikinEnergySensor, }[SENSOR_TYPES[monitored_state][CONF_TYPE]] return cls(device, monitored_state, period) @@ -102,6 +106,7 @@ def state(self): """Return the state of the sensor.""" raise NotImplementedError + @property def device_class(self): """Return the class of this device.""" @@ -139,8 +144,11 @@ def state(self): return self._device.outside_temperature return None + @property + def state_class(self): + return STATE_CLASS_MEASUREMENT -class DaikinPowerSensor(DaikinSensor): +class DaikinEnergySensor(DaikinSensor): """Representation of a power/energy consumption sensor.""" @property @@ -151,3 +159,7 @@ def state(self): if self._device_attribute == ATTR_HEAT_ENERGY: return round(self._device.energy_consumption("heating", self._period), 3) return None + + @property + def state_class(self): + return STATE_CLASS_TOTAL_INCREASING \ No newline at end of file