Fix last_reset in utility_meter (#55209)

This commit is contained in:
Erik Montnemery 2021-08-25 15:24:51 +02:00 committed by GitHub
parent 1224d68d05
commit 517fda1383
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ import logging
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
ATTR_LAST_RESET,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING, STATE_CLASS_TOTAL_INCREASING,
SensorEntity, SensorEntity,
@ -58,7 +59,6 @@ ATTR_SOURCE_ID = "source"
ATTR_STATUS = "status" ATTR_STATUS = "status"
ATTR_PERIOD = "meter_period" ATTR_PERIOD = "meter_period"
ATTR_LAST_PERIOD = "last_period" ATTR_LAST_PERIOD = "last_period"
ATTR_LAST_RESET = "last_reset"
ATTR_TARIFF = "tariff" ATTR_TARIFF = "tariff"
DEVICE_CLASS_MAP = { DEVICE_CLASS_MAP = {
@ -357,7 +357,6 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
ATTR_SOURCE_ID: self._sensor_source_id, ATTR_SOURCE_ID: self._sensor_source_id,
ATTR_STATUS: PAUSED if self._collecting is None else COLLECTING, ATTR_STATUS: PAUSED if self._collecting is None else COLLECTING,
ATTR_LAST_PERIOD: self._last_period, ATTR_LAST_PERIOD: self._last_period,
ATTR_LAST_RESET: self._last_reset.isoformat(),
} }
if self._period is not None: if self._period is not None:
state_attr[ATTR_PERIOD] = self._period state_attr[ATTR_PERIOD] = self._period
@ -369,3 +368,8 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
def icon(self): def icon(self):
"""Return the icon to use in the frontend, if any.""" """Return the icon to use in the frontend, if any."""
return ICON return ICON
@property
def last_reset(self):
"""Return the time when the sensor was last reset."""
return self._last_reset