Delay Plex websocket connection to avoid race (#28934)

This commit is contained in:
jjlawren 2019-11-21 14:39:24 -06:00 committed by Paulus Schoutsen
parent c015f94fa2
commit a62bd97fa5
2 changed files with 7 additions and 1 deletions

View File

@ -16,6 +16,7 @@ from homeassistant.const import (
CONF_TOKEN,
CONF_URL,
CONF_VERIFY_SSL,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.helpers import config_validation as cv
@ -164,12 +165,16 @@ async def async_setup_entry(hass, entry):
websocket = PlexWebsocket(
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
async def async_start_websocket_session(_):
await websocket.listen()
def close_websocket_session(_):
websocket.close()
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, async_start_websocket_session)
unsub = hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_STOP, close_websocket_session
)

View File

@ -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.data[PLEX_DOMAIN][DISPATCHERS][server_id].append(unsub)
_LOGGER.debug("New entity listener created")
@callback