mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Use _attr_last_reset to set last_reset (#65648)
This commit is contained in:
parent
98a7125933
commit
320df10a26
@ -8,7 +8,6 @@ import logging
|
||||
from iotawattpy.sensor import Sensor
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
ATTR_LAST_RESET,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
@ -211,6 +210,12 @@ class IotaWattSensor(update_coordinator.CoordinatorEntity, SensorEntity):
|
||||
else:
|
||||
self.hass.async_create_task(self.async_remove())
|
||||
return
|
||||
|
||||
if (begin := self._sensor_data.getBegin()) and (
|
||||
last_reset := dt.parse_datetime(begin)
|
||||
):
|
||||
self._attr_last_reset = last_reset
|
||||
|
||||
super()._handle_coordinator_update()
|
||||
|
||||
@property
|
||||
@ -220,8 +225,6 @@ class IotaWattSensor(update_coordinator.CoordinatorEntity, SensorEntity):
|
||||
attrs = {"type": data.getType()}
|
||||
if attrs["type"] == "Input":
|
||||
attrs["channel"] = data.getChannel()
|
||||
if (begin := data.getBegin()) and (last_reset := dt.parse_datetime(begin)):
|
||||
attrs[ATTR_LAST_RESET] = last_reset.isoformat()
|
||||
|
||||
return attrs
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user