Bugfix group reload (#5292)

* Bugfix group / hit update

* try to fix round 2

* Convert it to coro

* Don't check statemachine, check unsub listener.
This commit is contained in:
Pascal Vizeli 2017-01-13 12:29:20 +01:00 committed by Paulus Schoutsen
parent f7a1d63d52
commit baa8e53e66

View File

@ -359,13 +359,15 @@ class Group(Entity):
"""Start tracking members."""
run_callback_threadsafe(self.hass.loop, self.async_start).result()
@callback
def async_start(self):
"""Start tracking members.
This method must be run in the event loop.
"""
if self._async_unsub_state_changed is None:
self._async_unsub_state_changed = async_track_state_change(
self.hass, self.tracking, self._state_changed_listener
self.hass, self.tracking, self._async_state_changed_listener
)
def stop(self):
@ -392,20 +394,24 @@ class Group(Entity):
This method must be run in the event loop.
"""
yield from super().async_remove()
if self._async_unsub_state_changed:
self._async_unsub_state_changed()
self._async_unsub_state_changed = None
@callback
def _state_changed_listener(self, entity_id, old_state, new_state):
yield from super().async_remove()
@asyncio.coroutine
def _async_state_changed_listener(self, entity_id, old_state, new_state):
"""Respond to a member state changing.
This method must be run in the event loop.
"""
# removed
if self._async_unsub_state_changed is None:
return
self._async_update_group_state(new_state)
self.hass.async_add_job(self.async_update_ha_state())
yield from self.async_update_ha_state()
@property
def _tracking_states(self):