Add missing last_rest
in Tibber (#61914)
This commit is contained in:
parent
f3af0781f8
commit
04796c4410
1 changed files with 18 additions and 0 deletions
|
@ -455,6 +455,24 @@ class TibberSensorRT(TibberSensor, update_coordinator.CoordinatorEntity):
|
|||
state = live_measurement.get(self.entity_description.key)
|
||||
if state is None:
|
||||
return
|
||||
if self.entity_description.key in (
|
||||
"accumulatedConsumption",
|
||||
"accumulatedProduction",
|
||||
):
|
||||
# Value is reset to 0 at midnight, but not always strictly increasing due to hourly corrections
|
||||
# If device is offline, last_reset should be updated when it comes back online if the value has decreased
|
||||
ts_local = dt_util.parse_datetime(live_measurement["timestamp"])
|
||||
if ts_local is not None:
|
||||
if self.last_reset is None or (
|
||||
state < 0.5 * self.native_value # type: ignore # native_value is float
|
||||
and (
|
||||
ts_local.hour == 0
|
||||
or (ts_local - self.last_reset) > timedelta(hours=24)
|
||||
)
|
||||
):
|
||||
self._attr_last_reset = dt_util.as_utc(
|
||||
ts_local.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
)
|
||||
if self.entity_description.key == "powerFactor":
|
||||
state *= 100.0
|
||||
self._attr_native_value = state
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue