mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Unload Plex config entries (#26771)
* Unload config entries * Await coroutines * Unnecessary ensure
This commit is contained in:
parent
49fef9a6a0
commit
f82f30dc62
@ -1,4 +1,5 @@
|
||||
"""Support to embed Plex."""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
import plexapi.exceptions
|
||||
@ -21,6 +22,7 @@ from .const import (
|
||||
CONF_USE_EPISODE_ART,
|
||||
CONF_SHOW_ALL_CONTROLS,
|
||||
CONF_SERVER,
|
||||
CONF_SERVER_IDENTIFIER,
|
||||
DEFAULT_PORT,
|
||||
DEFAULT_SSL,
|
||||
DEFAULT_VERIFY_SSL,
|
||||
@ -28,6 +30,7 @@ from .const import (
|
||||
PLATFORMS,
|
||||
PLEX_MEDIA_PLAYER_OPTIONS,
|
||||
PLEX_SERVER_CONFIG,
|
||||
REFRESH_LISTENERS,
|
||||
SERVERS,
|
||||
)
|
||||
from .server import PlexServer
|
||||
@ -61,7 +64,7 @@ _LOGGER = logging.getLogger(__package__)
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the Plex component."""
|
||||
hass.data.setdefault(PLEX_DOMAIN, {SERVERS: {}})
|
||||
hass.data.setdefault(PLEX_DOMAIN, {SERVERS: {}, REFRESH_LISTENERS: {}})
|
||||
|
||||
plex_config = config.get(PLEX_DOMAIN, {})
|
||||
if plex_config:
|
||||
@ -129,3 +132,21 @@ async def async_setup_entry(hass, entry):
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass, entry):
|
||||
"""Unload a config entry."""
|
||||
server_id = entry.data[CONF_SERVER_IDENTIFIER]
|
||||
|
||||
cancel = hass.data[PLEX_DOMAIN][REFRESH_LISTENERS].pop(server_id)
|
||||
await hass.async_add_executor_job(cancel)
|
||||
|
||||
tasks = [
|
||||
hass.config_entries.async_forward_entry_unload(entry, platform)
|
||||
for platform in PLATFORMS
|
||||
]
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
hass.data[PLEX_DOMAIN][SERVERS].pop(server_id)
|
||||
|
||||
return True
|
||||
|
@ -7,6 +7,7 @@ DEFAULT_SSL = False
|
||||
DEFAULT_VERIFY_SSL = True
|
||||
|
||||
PLATFORMS = ["media_player", "sensor"]
|
||||
REFRESH_LISTENERS = "refresh_listeners"
|
||||
SERVERS = "servers"
|
||||
|
||||
PLEX_CONFIG_FILE = "plex.conf"
|
||||
|
@ -39,6 +39,7 @@ from .const import (
|
||||
DOMAIN as PLEX_DOMAIN,
|
||||
NAME_FORMAT,
|
||||
PLEX_MEDIA_PLAYER_OPTIONS,
|
||||
REFRESH_LISTENERS,
|
||||
SERVERS,
|
||||
)
|
||||
|
||||
@ -71,7 +72,9 @@ def _setup_platform(hass, config_entry, add_entities_callback):
|
||||
plexserver = hass.data[PLEX_DOMAIN][SERVERS][server_id]
|
||||
plex_clients = {}
|
||||
plex_sessions = {}
|
||||
track_time_interval(hass, lambda now: update_devices(), timedelta(seconds=10))
|
||||
hass.data[PLEX_DOMAIN][REFRESH_LISTENERS][server_id] = track_time_interval(
|
||||
hass, lambda now: update_devices(), timedelta(seconds=10)
|
||||
)
|
||||
|
||||
def update_devices():
|
||||
"""Update the devices objects."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user