Directly call write state 2 (#33513)

* Directly call async_write_ha_state pt2

* Directly call async_write_ha_state pt2

* Fix mock

* Address comments
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-04-03 09:34:50 +02:00
1 parent 83cc871edf
commit aef06a3544
40 files changed
+127 -117

No files matched your search

@@ -217,7 +217,7 @@ class UtilityMeterSensor(RestoreEntity):
self._last_reset = dt_util.now()
self._last_period = str(self._state)
self._state = 0
await self.async_update_ha_state()
self.async_write_ha_state()
async def async_calibrate(self, value):
"""Calibrate the Utility Meter with a given value."""
@@ -253,7 +253,7 @@ class UtilityMeterSensor(RestoreEntity):
self._unit_of_measurement = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
self._last_period = state.attributes.get(ATTR_LAST_PERIOD)
self._last_reset = state.attributes.get(ATTR_LAST_RESET)
await self.async_update_ha_state()
self.async_write_ha_state()
if state.attributes.get(ATTR_STATUS) == PAUSED:
# Fake cancellation function to init the meter paused
self._collecting = lambda: None