From 6e0739499c153efde7e6442feacd23d863f8f14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicklas=20Sj=C3=B6qvist?= <30925204+SeaquestNet@users.noreply.github.com> Date: Thu, 30 Sep 2021 14:30:08 +0200 Subject: [PATCH] changing state_class for energy sensor (#34) * changing state_class for energy sensor Changing NgenicEnergySensor state_class to STATE_CLASS_TOTAL_INCREASING. This will ensure statistics are calculated correctly (instead of being treated as current measurement). * remove last reset from NgenicEnergySensor --- custom_components/ngenic/sensor.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/custom_components/ngenic/sensor.py b/custom_components/ngenic/sensor.py index 726afe8..d6a242b 100644 --- a/custom_components/ngenic/sensor.py +++ b/custom_components/ngenic/sensor.py @@ -14,7 +14,7 @@ ENERGY_KILO_WATT_HOUR, POWER_WATT ) -from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity +from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, SensorEntity from homeassistant.helpers.event import async_track_time_interval import homeassistant.util.dt as dt_util @@ -341,18 +341,13 @@ async def _async_fetch_measurement(self): class NgenicEnergySensor(NgenicSensor): device_class = DEVICE_CLASS_ENERGY - state_class = STATE_CLASS_MEASUREMENT + state_class = STATE_CLASS_TOTAL_INCREASING @property def unit_of_measurement(self): """Return the unit of measurement.""" return ENERGY_KILO_WATT_HOUR - @property - def last_reset(self): - """Return the time when the sensor value was last reset.""" - return dt_util.start_of_local_day() - async def _async_fetch_measurement(self): """Ask for measurements for a duration. This requires some further inputs, so we'll override the _async_fetch_measurement method.