Skip to content

Commit

Permalink
Introduced LTS support for Energy sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
rospogrigio committed Jan 25, 2022
1 parent a4ec95d commit 61ad7b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions custom_components/daikin_residential/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
CONF_TYPE,
CONF_UNIT_OF_MEASUREMENT,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
TEMP_CELSIUS,
)
Expand Down Expand Up @@ -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,
},
}
Expand Down
22 changes: 17 additions & 5 deletions custom_components/daikin_residential/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 61ad7b7

Please sign in to comment.