Use _attr_last_reset to set last_reset (#65648)

This commit is contained in:
Stefan Agner 2022-02-04 11:40:38 +01:00 committed by GitHub
parent 98a7125933
commit 320df10a26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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