This commit is contained in:
Diogo Gomes
2022-02-13 23:28:46 +00:00
parent 1b27011320
commit 1d082d3ca6

View File

@@ -32,6 +32,7 @@ from homeassistant.helpers.event import (
async_track_state_change_event, async_track_state_change_event,
) )
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.template import is_number
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@@ -321,6 +322,7 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
self._last_period = ( self._last_period = (
float(state.attributes.get(ATTR_LAST_PERIOD)) float(state.attributes.get(ATTR_LAST_PERIOD))
if state.attributes.get(ATTR_LAST_PERIOD) if state.attributes.get(ATTR_LAST_PERIOD)
and is_number(state.attributes.get(ATTR_LAST_PERIOD))
else 0 else 0
) )
self._last_reset = dt_util.as_utc( self._last_reset = dt_util.as_utc(