mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Trigger Plex GDM scans regularly (#48041)
This commit is contained in:
parent
40ce25800c
commit
e5893ca42c
@ -61,12 +61,16 @@ async def async_setup(hass, config):
|
|||||||
|
|
||||||
gdm = hass.data[PLEX_DOMAIN][GDM_SCANNER] = GDM()
|
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.data[PLEX_DOMAIN][GDM_DEBOUNCER] = Debouncer(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
cooldown=10,
|
cooldown=10,
|
||||||
immediate=True,
|
immediate=True,
|
||||||
function=partial(gdm.scan, scan_for_clients=True),
|
function=gdm_scan,
|
||||||
).async_call
|
).async_call
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -145,14 +149,10 @@ async def async_setup_entry(hass, entry):
|
|||||||
|
|
||||||
entry.add_update_listener(async_options_updated)
|
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(
|
unsub = async_dispatcher_connect(
|
||||||
hass,
|
hass,
|
||||||
PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id),
|
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].setdefault(server_id, [])
|
||||||
hass.data[PLEX_DOMAIN][DISPATCHERS][server_id].append(unsub)
|
hass.data[PLEX_DOMAIN][DISPATCHERS][server_id].append(unsub)
|
||||||
@ -164,7 +164,7 @@ async def async_setup_entry(hass, entry):
|
|||||||
|
|
||||||
if data == STATE_CONNECTED:
|
if data == STATE_CONNECTED:
|
||||||
_LOGGER.debug("Websocket to %s successful", entry.data[CONF_SERVER])
|
_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:
|
elif data == STATE_DISCONNECTED:
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Websocket to %s disconnected, retrying", entry.data[CONF_SERVER]
|
"Websocket to %s disconnected, retrying", entry.data[CONF_SERVER]
|
||||||
|
@ -34,6 +34,7 @@ from .const import (
|
|||||||
DEBOUNCE_TIMEOUT,
|
DEBOUNCE_TIMEOUT,
|
||||||
DEFAULT_VERIFY_SSL,
|
DEFAULT_VERIFY_SSL,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
GDM_DEBOUNCER,
|
||||||
GDM_SCANNER,
|
GDM_SCANNER,
|
||||||
PLAYER_SOURCE,
|
PLAYER_SOURCE,
|
||||||
PLEX_NEW_MP_SIGNAL,
|
PLEX_NEW_MP_SIGNAL,
|
||||||
@ -323,6 +324,8 @@ class PlexServer:
|
|||||||
"""Update the platform entities."""
|
"""Update the platform entities."""
|
||||||
_LOGGER.debug("Updating devices")
|
_LOGGER.debug("Updating devices")
|
||||||
|
|
||||||
|
await self.hass.data[DOMAIN][GDM_DEBOUNCER]()
|
||||||
|
|
||||||
available_clients = {}
|
available_clients = {}
|
||||||
ignored_clients = set()
|
ignored_clients = set()
|
||||||
new_clients = set()
|
new_clients = set()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user