mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Add missing last_rest
in Tibber (#61914)
This commit is contained in:
parent
f3af0781f8
commit
04796c4410
@ -455,6 +455,24 @@ class TibberSensorRT(TibberSensor, update_coordinator.CoordinatorEntity):
|
|||||||
state = live_measurement.get(self.entity_description.key)
|
state = live_measurement.get(self.entity_description.key)
|
||||||
if state is None:
|
if state is None:
|
||||||
return
|
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":
|
if self.entity_description.key == "powerFactor":
|
||||||
state *= 100.0
|
state *= 100.0
|
||||||
self._attr_native_value = state
|
self._attr_native_value = state
|
||||||
|
Loading…
x
Reference in New Issue
Block a user