mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use ConfigEntry.async_on_unload in UpCloud (#49784)
This commit is contained in:
parent
458ca970c9
commit
5e00fdccfd
@ -21,7 +21,7 @@ from homeassistant.const import (
|
|||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_PROBLEM,
|
STATE_PROBLEM,
|
||||||
)
|
)
|
||||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
@ -91,7 +91,6 @@ class UpCloudDataUpdateCoordinator(
|
|||||||
hass, _LOGGER, name=f"{username}@UpCloud", update_interval=update_interval
|
hass, _LOGGER, name=f"{username}@UpCloud", update_interval=update_interval
|
||||||
)
|
)
|
||||||
self.cloud_manager = cloud_manager
|
self.cloud_manager = cloud_manager
|
||||||
self.unsub_handlers: list[CALLBACK_TYPE] = []
|
|
||||||
|
|
||||||
async def async_update_config(self, config_entry: ConfigEntry) -> None:
|
async def async_update_config(self, config_entry: ConfigEntry) -> None:
|
||||||
"""Handle config update."""
|
"""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()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
# Listen to config entry updates
|
# Listen to config entry updates
|
||||||
coordinator.unsub_handlers.append(
|
config_entry.async_on_unload(
|
||||||
config_entry.add_update_listener(_async_signal_options_update)
|
config_entry.add_update_listener(_async_signal_options_update)
|
||||||
)
|
)
|
||||||
coordinator.unsub_handlers.append(
|
config_entry.async_on_unload(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
hass,
|
hass,
|
||||||
_config_entry_update_signal_name(config_entry),
|
_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:
|
for domain in CONFIG_ENTRY_DOMAINS:
|
||||||
await hass.config_entries.async_forward_entry_unload(config_entry, domain)
|
await hass.config_entries.async_forward_entry_unload(config_entry, domain)
|
||||||
|
|
||||||
coordinator: UpCloudDataUpdateCoordinator = hass.data[
|
hass.data[DATA_UPCLOUD].coordinators.pop(config_entry.data[CONF_USERNAME])
|
||||||
DATA_UPCLOUD
|
|
||||||
].coordinators.pop(config_entry.data[CONF_USERNAME])
|
|
||||||
while coordinator.unsub_handlers:
|
|
||||||
coordinator.unsub_handlers.pop()()
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user