Cleanup and simplitfy the async state update (#9390)

* Cleanup and simplitfy the async state update

* Update test_entity.py
This commit is contained in:
Pascal Vizeli authored and GitHub committed 2017-09-12 10:01:03 +02:00
1 parent c84a099b0f
commit 90f9a6bc0a
47 files changed
+128 -102

No files matched your search

@@ -72,7 +72,7 @@ class IPWebcamSettingsSwitch(AndroidIPCamEntity, SwitchDevice):
else:
yield from self._ipcam.change_setting(self._setting, True)
self._state = True
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
@asyncio.coroutine
def async_turn_off(self, **kwargs):
@@ -86,7 +86,7 @@ class IPWebcamSettingsSwitch(AndroidIPCamEntity, SwitchDevice):
else:
yield from self._ipcam.change_setting(self._setting, False)
self._state = False
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
@property
def icon(self):
+4 -4
View File
@@ -111,7 +111,7 @@ class MqttSwitch(SwitchDevice):
elif payload == self._payload_off:
self._state = False
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
@callback
def availability_message_received(topic, payload, qos):
@@ -121,7 +121,7 @@ class MqttSwitch(SwitchDevice):
elif payload == self._payload_not_available:
self._available = False
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
if self._state_topic is None:
# Force into optimistic mode.
@@ -173,7 +173,7 @@ class MqttSwitch(SwitchDevice):
if self._optimistic:
# Optimistically assume that switch has changed state.
self._state = True
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
@asyncio.coroutine
def async_turn_off(self, **kwargs):
@@ -187,4 +187,4 @@ class MqttSwitch(SwitchDevice):
if self._optimistic:
# Optimistically assume that switch has changed state.
self._state = False
self.hass.async_add_job(self.async_update_ha_state())
self.async_schedule_update_ha_state()
+2 -2
View File
@@ -103,7 +103,7 @@ class SwitchTemplate(SwitchDevice):
@callback
def template_switch_state_listener(entity, old_state, new_state):
"""Handle target device state changes."""
self.hass.async_add_job(self.async_update_ha_state(True))
self.async_schedule_update_ha_state(True)
@callback
def template_switch_startup(event):
@@ -111,7 +111,7 @@ class SwitchTemplate(SwitchDevice):
async_track_state_change(
self.hass, self._entities, template_switch_state_listener)
self.hass.async_add_job(self.async_update_ha_state(True))
self.async_schedule_update_ha_state(True)
self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_START, template_switch_startup)