mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Set last_reset for integrated entities in IoTaWatt (#65143)
* Set last_reset for integrated entities For entities which integrate over time (like energy in watt hours) the iotawattpy library uses the beginning of the year as start date by default (using relative time specification "y", see [1]). Since PR #56974 state class has been changed from TOTAL_INCREASING to TOTAL. However, the relative start date of "y" causes the value to reset to zero at the beginning of the year. This fixes it by setting last_reset properly, which takes such resets into account. While at it, let's set the cycle to one day. This lowers the load on IoTaWatt (fetching with start date beginning of the day seems to response faster than beginning of the year). [1]: https://docs.iotawatt.com/en/master/query.html#relative-time * Update homeassistant/components/iotawatt/sensor.py * Update homeassistant/components/iotawatt/coordinator.py Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
530fc8a9af
commit
c8e64358b1
@ -51,6 +51,7 @@ class IotawattUpdater(DataUpdateCoordinator):
|
|||||||
httpx_client.get_async_client(self.hass),
|
httpx_client.get_async_client(self.hass),
|
||||||
self.entry.data.get(CONF_USERNAME),
|
self.entry.data.get(CONF_USERNAME),
|
||||||
self.entry.data.get(CONF_PASSWORD),
|
self.entry.data.get(CONF_PASSWORD),
|
||||||
|
integratedInterval="d",
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
is_authenticated = await api.connect()
|
is_authenticated = await api.connect()
|
||||||
|
@ -8,6 +8,7 @@ import logging
|
|||||||
from iotawattpy.sensor import Sensor
|
from iotawattpy.sensor import Sensor
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
|
ATTR_LAST_RESET,
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
@ -219,6 +220,9 @@ class IotaWattSensor(update_coordinator.CoordinatorEntity, SensorEntity):
|
|||||||
attrs = {"type": data.getType()}
|
attrs = {"type": data.getType()}
|
||||||
if attrs["type"] == "Input":
|
if attrs["type"] == "Input":
|
||||||
attrs["channel"] = data.getChannel()
|
attrs["channel"] = data.getChannel()
|
||||||
|
if (begin := data.getBegin()) and (last_reset := dt.parse_datetime(begin)):
|
||||||
|
attrs[ATTR_LAST_RESET] = last_reset.isoformat()
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user