Use ConfigEntry.async_on_unload in UpCloud (#49784)

This commit is contained in:
Ville Skyttä 2021-04-27 22:41:03 +03:00 committed by GitHub
parent 458ca970c9
commit 5e00fdccfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,7 @@ from homeassistant.const import (
STATE_ON,
STATE_PROBLEM,
)
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import (
@ -91,7 +91,6 @@ class UpCloudDataUpdateCoordinator(
hass, _LOGGER, name=f"{username}@UpCloud", update_interval=update_interval
)
self.cloud_manager = cloud_manager
self.unsub_handlers: list[CALLBACK_TYPE] = []
async def async_update_config(self, config_entry: ConfigEntry) -> None:
"""Handle config update."""
@ -210,10 +209,10 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
await coordinator.async_config_entry_first_refresh()
# Listen to config entry updates
coordinator.unsub_handlers.append(
config_entry.async_on_unload(
config_entry.add_update_listener(_async_signal_options_update)
)
coordinator.unsub_handlers.append(
config_entry.async_on_unload(
async_dispatcher_connect(
hass,
_config_entry_update_signal_name(config_entry),
@ -237,11 +236,7 @@ async def async_unload_entry(hass, config_entry):
for domain in CONFIG_ENTRY_DOMAINS:
await hass.config_entries.async_forward_entry_unload(config_entry, domain)
coordinator: UpCloudDataUpdateCoordinator = hass.data[
DATA_UPCLOUD
].coordinators.pop(config_entry.data[CONF_USERNAME])
while coordinator.unsub_handlers:
coordinator.unsub_handlers.pop()()
hass.data[DATA_UPCLOUD].coordinators.pop(config_entry.data[CONF_USERNAME])
return True