mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Delay Plex websocket connection to avoid race (#28934)
This commit is contained in:
parent
c015f94fa2
commit
a62bd97fa5
@ -16,6 +16,7 @@ from homeassistant.const import (
|
|||||||
CONF_TOKEN,
|
CONF_TOKEN,
|
||||||
CONF_URL,
|
CONF_URL,
|
||||||
CONF_VERIFY_SSL,
|
CONF_VERIFY_SSL,
|
||||||
|
EVENT_HOMEASSISTANT_START,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
@ -164,12 +165,16 @@ async def async_setup_entry(hass, entry):
|
|||||||
websocket = PlexWebsocket(
|
websocket = PlexWebsocket(
|
||||||
plex_server.plex_server, update_plex, session=session, verify_ssl=verify_ssl
|
plex_server.plex_server, update_plex, session=session, verify_ssl=verify_ssl
|
||||||
)
|
)
|
||||||
hass.loop.create_task(websocket.listen())
|
|
||||||
hass.data[PLEX_DOMAIN][WEBSOCKETS][server_id] = websocket
|
hass.data[PLEX_DOMAIN][WEBSOCKETS][server_id] = websocket
|
||||||
|
|
||||||
|
async def async_start_websocket_session(_):
|
||||||
|
await websocket.listen()
|
||||||
|
|
||||||
def close_websocket_session(_):
|
def close_websocket_session(_):
|
||||||
websocket.close()
|
websocket.close()
|
||||||
|
|
||||||
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, async_start_websocket_session)
|
||||||
|
|
||||||
unsub = hass.bus.async_listen_once(
|
unsub = hass.bus.async_listen_once(
|
||||||
EVENT_HOMEASSISTANT_STOP, close_websocket_session
|
EVENT_HOMEASSISTANT_STOP, close_websocket_session
|
||||||
)
|
)
|
||||||
|
@ -68,6 +68,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
hass, PLEX_NEW_MP_SIGNAL.format(server_id), async_new_media_players
|
hass, PLEX_NEW_MP_SIGNAL.format(server_id), async_new_media_players
|
||||||
)
|
)
|
||||||
hass.data[PLEX_DOMAIN][DISPATCHERS][server_id].append(unsub)
|
hass.data[PLEX_DOMAIN][DISPATCHERS][server_id].append(unsub)
|
||||||
|
_LOGGER.debug("New entity listener created")
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
Loading…
x
Reference in New Issue
Block a user