Trigger Plex GDM scans regularly (#48041)

This commit is contained in:
jjlawren 2021-03-22 00:14:09 -05:00 committed by GitHub
parent 40ce25800c
commit e5893ca42c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View file

@ -61,12 +61,16 @@ async def async_setup(hass, config):
gdm = hass.data[PLEX_DOMAIN][GDM_SCANNER] = GDM()
def gdm_scan():
_LOGGER.debug("Scanning for GDM clients")
gdm.scan(scan_for_clients=True)
hass.data[PLEX_DOMAIN][GDM_DEBOUNCER] = Debouncer(
hass,
_LOGGER,
cooldown=10,
immediate=True,
function=partial(gdm.scan, scan_for_clients=True),
function=gdm_scan,
).async_call
return True
@ -145,14 +149,10 @@ async def async_setup_entry(hass, entry):
entry.add_update_listener(async_options_updated)
async def async_update_plex():
await hass.data[PLEX_DOMAIN][GDM_DEBOUNCER]()
await plex_server.async_update_platforms()
unsub = async_dispatcher_connect(
hass,
PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id),
async_update_plex,
plex_server.async_update_platforms,
)
hass.data[PLEX_DOMAIN][DISPATCHERS].setdefault(server_id, [])
hass.data[PLEX_DOMAIN][DISPATCHERS][server_id].append(unsub)
@ -164,7 +164,7 @@ async def async_setup_entry(hass, entry):
if data == STATE_CONNECTED:
_LOGGER.debug("Websocket to %s successful", entry.data[CONF_SERVER])
hass.async_create_task(async_update_plex())
hass.async_create_task(plex_server.async_update_platforms())
elif data == STATE_DISCONNECTED:
_LOGGER.debug(
"Websocket to %s disconnected, retrying", entry.data[CONF_SERVER]

View file

@ -34,6 +34,7 @@ from .const import (
DEBOUNCE_TIMEOUT,
DEFAULT_VERIFY_SSL,
DOMAIN,
GDM_DEBOUNCER,
GDM_SCANNER,
PLAYER_SOURCE,
PLEX_NEW_MP_SIGNAL,
@ -323,6 +324,8 @@ class PlexServer:
"""Update the platform entities."""
_LOGGER.debug("Updating devices")
await self.hass.data[DOMAIN][GDM_DEBOUNCER]()
available_clients = {}
ignored_clients = set()
new_clients = set()