Skip to content

Commit

Permalink
Add support for long term stats
Browse files Browse the repository at this point in the history
  • Loading branch information
roleoroleo committed Jan 10, 2022
1 parent e274ab8 commit b3204f0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion custom_components/4_noks/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TIMESTAMP,
SensorEntity)
SensorEntity,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (CONF_HOST, CONF_NAME)
from homeassistant.core import HomeAssistant, callback
Expand Down Expand Up @@ -80,14 +82,18 @@ def __init__(self, coordinator, config, sensor_name, sensor_um):
self._um = sensor_um
if (self._um.lower() == "kw"):
self._device_class = DEVICE_CLASS_POWER
self._state_class = STATE_CLASS_MEASUREMENT
elif (self._um.lower() == "kwh"):
self._device_class = DEVICE_CLASS_ENERGY
self._state_class = STATE_CLASS_TOTAL_INCREASING
elif (self._um.lower() == "dd/mm/yyyy hh:mm:ss"):
self._um = ""
# self._device_class = DEVICE_CLASS_TIMESTAMP
self._device_class = None
self._state_class = None
else:
self._device_class = None
self._state_class = None

@property
def name(self):
Expand Down Expand Up @@ -123,6 +129,11 @@ def device_class(self):
"""Return the icon to use in the frontend."""
return self._device_class

@property
def state_class(self):
"""Return state class."""
return self._state_class

@property
def device_info(self):
"""Return device specific attributes."""
Expand Down

0 comments on commit b3204f0

Please sign in to comment.