Skip to content

Commit

Permalink
Delay Plex websocket connection to avoid race (#28934)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjlawren authored and balloob committed Nov 21, 2019
1 parent 3391fc6 commit ab9a60f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion homeassistant/components/plex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CONF_TOKEN,
CONF_URL,
CONF_VERIFY_SSL,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.helpers import config_validation as cv
Expand Down Expand Up @@ -164,12 +165,16 @@ def update_plex():
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
)
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/plex/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def async_new_media_players(new_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
Expand Down

0 comments on commit ab9a60f

Please sign in to comment.