mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Remove yeelight init dispatcher on unloading (#45359)
This commit is contained in:
parent
ab62a4ce39
commit
e46f1c0a10
@ -49,6 +49,7 @@ DATA_CUSTOM_EFFECTS = "custom_effects"
|
||||
DATA_SCAN_INTERVAL = "scan_interval"
|
||||
DATA_DEVICE = "device"
|
||||
DATA_UNSUB_UPDATE_LISTENER = "unsub_update_listener"
|
||||
DATA_REMOVE_INIT_DISPATCHER = "remove_init_dispatcher"
|
||||
|
||||
ATTR_COUNT = "count"
|
||||
ATTR_ACTION = "action"
|
||||
@ -182,11 +183,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Yeelight from a config entry."""
|
||||
|
||||
async def _initialize(host: str, capabilities: Optional[dict] = None) -> None:
|
||||
async_dispatcher_connect(
|
||||
remove_dispatcher = async_dispatcher_connect(
|
||||
hass,
|
||||
DEVICE_INITIALIZED.format(host),
|
||||
_load_platforms,
|
||||
)
|
||||
hass.data[DOMAIN][DATA_CONFIG_ENTRIES][entry.entry_id][
|
||||
DATA_REMOVE_INIT_DISPATCHER
|
||||
] = remove_dispatcher
|
||||
|
||||
device = await _async_get_device(hass, host, entry, capabilities)
|
||||
hass.data[DOMAIN][DATA_CONFIG_ENTRIES][entry.entry_id][DATA_DEVICE] = device
|
||||
@ -251,6 +255,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
|
||||
if unload_ok:
|
||||
data = hass.data[DOMAIN][DATA_CONFIG_ENTRIES].pop(entry.entry_id)
|
||||
remove_init_dispatcher = data.get(DATA_REMOVE_INIT_DISPATCHER)
|
||||
if remove_init_dispatcher is not None:
|
||||
remove_init_dispatcher()
|
||||
data[DATA_UNSUB_UPDATE_LISTENER]()
|
||||
data[DATA_DEVICE].async_unload()
|
||||
if entry.data[CONF_ID]:
|
||||
|
Loading…
x
Reference in New Issue
Block a user