From 5e00fdccfdf7eb335d69fb240fb7a850d3758ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Tue, 27 Apr 2021 22:41:03 +0300 Subject: [PATCH] Use ConfigEntry.async_on_unload in UpCloud (#49784) --- homeassistant/components/upcloud/__init__.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/upcloud/__init__.py b/homeassistant/components/upcloud/__init__.py index 4f13aaa5460..d3835f30bd9 100644 --- a/homeassistant/components/upcloud/__init__.py +++ b/homeassistant/components/upcloud/__init__.py @@ -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