Streamline Notion CoordinatorEntity (#43027)

This commit is contained in:
Aaron Bach 2020-11-10 01:24:27 -07:00 committed by GitHub
parent 244bfb2096
commit 49b4f9d2c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -246,15 +246,13 @@ class NotionEntity(CoordinatorEntity):
"""Update the entity from the latest data."""
raise NotImplementedError
async def async_added_to_hass(self) -> None:
"""Register callbacks."""
@callback
def update():
"""Update the state."""
self._async_update_from_latest_data()
self.async_write_ha_state()
self.async_on_remove(self.coordinator.async_add_listener(update))
@callback
def _handle_coordinator_update(self):
"""Respond to a DataUpdateCoordinator update."""
self._async_update_from_latest_data()
self.async_write_ha_state()
async def async_added_to_hass(self):
"""Handle entity which will be added."""
await super().async_added_to_hass()
self._async_update_from_latest_data()