Repository event subscription (#67284)

This commit is contained in:
Joakim Sørensen 2022-02-26 15:56:36 +01:00 committed by GitHub
parent 73fdd47d54
commit e65670fef4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 7 deletions

View file

@ -38,6 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
await coordinator.async_config_entry_first_refresh()
await coordinator.subscribe()
hass.data[DOMAIN][repository] = coordinator
@ -45,7 +46,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(async_reload_entry))
return True
@ -77,6 +77,10 @@ def async_cleanup_device_registry(
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
repositories: dict[str, GitHubDataUpdateCoordinator] = hass.data[DOMAIN]
for coordinator in repositories.values():
coordinator.unsubscribe()
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data.pop(DOMAIN)
return unload_ok