Change utility_meter last_reset timestamps to UTC (#51067)

This commit is contained in:
Erik Montnemery 2021-05-25 15:46:54 +02:00 committed by GitHub
parent 67804ee5df
commit ae8652217c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -131,7 +131,7 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
self._sensor_source_id = source_entity self._sensor_source_id = source_entity
self._state = 0 self._state = 0
self._last_period = 0 self._last_period = 0
self._last_reset = dt_util.now() self._last_reset = dt_util.utcnow()
self._collecting = None self._collecting = None
if name: if name:
self._name = name self._name = name
@ -237,7 +237,7 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
if self._tariff_entity != entity_id: if self._tariff_entity != entity_id:
return return
_LOGGER.debug("Reset utility meter <%s>", self.entity_id) _LOGGER.debug("Reset utility meter <%s>", self.entity_id)
self._last_reset = dt_util.now() self._last_reset = dt_util.utcnow()
self._last_period = str(self._state) self._last_period = str(self._state)
self._state = 0 self._state = 0
self.async_write_ha_state() self.async_write_ha_state()
@ -284,8 +284,8 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
self._state = Decimal(state.state) self._state = Decimal(state.state)
self._unit_of_measurement = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) self._unit_of_measurement = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
self._last_period = state.attributes.get(ATTR_LAST_PERIOD) self._last_period = state.attributes.get(ATTR_LAST_PERIOD)
self._last_reset = dt_util.parse_datetime( self._last_reset = dt_util.as_utc(
state.attributes.get(ATTR_LAST_RESET) dt_util.parse_datetime(state.attributes.get(ATTR_LAST_RESET))
) )
if state.attributes.get(ATTR_STATUS) == COLLECTING: if state.attributes.get(ATTR_STATUS) == COLLECTING:
# Fake cancellation function to init the meter in similar state # Fake cancellation function to init the meter in similar state