mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Simplify remove listener in kodi (#147183)
This commit is contained in:
parent
973700542b
commit
e23cac8bef
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user