Simplify remove listener in kodi (#147183)

This commit is contained in:
epenet 2025-06-20 10:23:41 +02:00 committed by GitHub
parent 973700542b
commit e23cac8bef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 11 deletions

View File

@ -17,13 +17,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import ( from .const import CONF_WS_PORT, DATA_CONNECTION, DATA_KODI, DOMAIN
CONF_WS_PORT,
DATA_CONNECTION,
DATA_KODI,
DATA_REMOVE_LISTENER,
DOMAIN,
)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
PLATFORMS = [Platform.MEDIA_PLAYER] PLATFORMS = [Platform.MEDIA_PLAYER]
@ -58,13 +52,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def _close(event): async def _close(event):
await conn.close() await conn.close()
remove_stop_listener = hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _close) entry.async_on_unload(hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _close))
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = { hass.data[DOMAIN][entry.entry_id] = {
DATA_CONNECTION: conn, DATA_CONNECTION: conn,
DATA_KODI: kodi, DATA_KODI: kodi,
DATA_REMOVE_LISTENER: remove_stop_listener,
} }
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
@ -78,6 +71,5 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if unload_ok: if unload_ok:
data = hass.data[DOMAIN].pop(entry.entry_id) data = hass.data[DOMAIN].pop(entry.entry_id)
await data[DATA_CONNECTION].close() await data[DATA_CONNECTION].close()
data[DATA_REMOVE_LISTENER]()
return unload_ok return unload_ok

View File

@ -6,7 +6,6 @@ CONF_WS_PORT = "ws_port"
DATA_CONNECTION = "connection" DATA_CONNECTION = "connection"
DATA_KODI = "kodi" DATA_KODI = "kodi"
DATA_REMOVE_LISTENER = "remove_listener"
DEFAULT_PORT = 8080 DEFAULT_PORT = 8080
DEFAULT_SSL = False DEFAULT_SSL = False