mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Move Nanoleaf event canceling (#119909)
* Move Nanoleaf event canceling * Fix * Fix
This commit is contained in:
parent
d9c7887bbf
commit
52bf3a028f
@ -3,6 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from contextlib import suppress
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -34,7 +35,6 @@ class NanoleafEntryData:
|
|||||||
|
|
||||||
device: Nanoleaf
|
device: Nanoleaf
|
||||||
coordinator: NanoleafCoordinator
|
coordinator: NanoleafCoordinator
|
||||||
event_listener: asyncio.Task
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
@ -80,8 +80,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def _cancel_listener() -> None:
|
||||||
|
event_listener.cancel()
|
||||||
|
with suppress(asyncio.CancelledError):
|
||||||
|
await event_listener
|
||||||
|
|
||||||
|
entry.async_on_unload(_cancel_listener)
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = NanoleafEntryData(
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = NanoleafEntryData(
|
||||||
nanoleaf, coordinator, event_listener
|
nanoleaf, coordinator
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
@ -91,7 +98,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||||
entry_data: NanoleafEntryData = hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
entry_data.event_listener.cancel()
|
return unload_ok
|
||||||
return True
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user