Introduce Entity.async_write_ha_state() to not miss state transition (#21590)

* Copy state in schedule_update_ha_state

* Lint

* Fix broken test

* Review comment, improve docstring

* Preserve order of state updates

* Rewrite

* Break up async_update_ha_state

* Update binary_sensor.py

* Review comments

* Update docstring

* hass -> ha

* Update entity.py

* Update entity.py
This commit is contained in:
emontnemery authored and Paulus Schoutsen committed 2019-03-09 09:52:22 -08:00
1 parent 458548daec
commit fc81826763
3 files changed
+38 -7

No files matched your search

@@ -117,7 +117,7 @@ class MqttBinarySensor(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
await self.availability_discovery_update(config)
await self.device_info_discovery_update(config)
await self._subscribe_topics()
self.async_schedule_update_ha_state()
self.async_write_ha_state()
async def _subscribe_topics(self):
"""(Re)Subscribe to topics."""
@@ -130,7 +130,7 @@ class MqttBinarySensor(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
"""Switch device off after a delay."""
self._delay_listener = None
self._state = False
self.async_schedule_update_ha_state()
self.async_write_ha_state()
@callback
def state_message_received(_topic, payload, _qos):
@@ -159,7 +159,7 @@ class MqttBinarySensor(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
self._delay_listener = evt.async_call_later(
self.hass, off_delay, off_delay_listener)
self.async_schedule_update_ha_state()
self.async_write_ha_state()
self._sub_state = await subscription.async_subscribe_topics(
self.hass, self._sub_state,