Skip to content

Commit

Permalink
changing state_class for energy sensor (#34)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SeaquestNet authored Sep 30, 2021
1 parent cfb541f commit 6e07394
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions custom_components/ngenic/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit 6e07394

Please sign in to comment.