Refactor august to use self.async_on_remove (#42333)

This commit is contained in:
J. Nick Koston 2020-10-25 07:27:51 -05:00 committed by GitHub
parent 6822190772
commit 3f18cdc75e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 14 deletions

View file

@ -46,18 +46,13 @@ class AugustEntityMixin(Entity):
async def async_added_to_hass(self):
"""Subscribe to updates."""
self._data.async_subscribe_device_id(
self._device_id, self._update_from_data_and_write_state
self.async_on_remove(
self._data.async_subscribe_device_id(
self._device_id, self._update_from_data_and_write_state
)
)
self._data.activity_stream.async_subscribe_device_id(
self._device_id, self._update_from_data_and_write_state
)
async def async_will_remove_from_hass(self):
"""Undo subscription."""
self._data.async_unsubscribe_device_id(
self._device_id, self._update_from_data_and_write_state
)
self._data.activity_stream.async_unsubscribe_device_id(
self._device_id, self._update_from_data_and_write_state
self.async_on_remove(
self._data.activity_stream.async_subscribe_device_id(
self._device_id, self._update_from_data_and_write_state
)
)