mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Refactor Plex device/session updates (#34616)
This commit is contained in:
parent
f94329dbbd
commit
c582911879
@ -207,36 +207,37 @@ class PlexServer:
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
for device in devices:
|
def process_device(source, device):
|
||||||
self._known_idle.discard(device.machineIdentifier)
|
self._known_idle.discard(device.machineIdentifier)
|
||||||
available_clients[device.machineIdentifier] = {"device": device}
|
available_clients.setdefault(device.machineIdentifier, {"device": device})
|
||||||
|
|
||||||
if device.machineIdentifier not in self._known_clients:
|
if device.machineIdentifier not in self._known_clients:
|
||||||
new_clients.add(device.machineIdentifier)
|
new_clients.add(device.machineIdentifier)
|
||||||
_LOGGER.debug("New device: %s", device.machineIdentifier)
|
_LOGGER.debug(
|
||||||
|
"New %s %s: %s", device.product, source, device.machineIdentifier
|
||||||
|
)
|
||||||
|
|
||||||
|
for device in devices:
|
||||||
|
process_device("device", device)
|
||||||
|
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
if session.TYPE == "photo":
|
if session.TYPE == "photo":
|
||||||
_LOGGER.debug("Photo session detected, skipping: %s", session)
|
_LOGGER.debug("Photo session detected, skipping: %s", session)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
session_username = session.usernames[0]
|
session_username = session.usernames[0]
|
||||||
for player in session.players:
|
for player in session.players:
|
||||||
if session_username and session_username not in monitored_users:
|
if session_username and session_username not in monitored_users:
|
||||||
ignored_clients.add(player.machineIdentifier)
|
ignored_clients.add(player.machineIdentifier)
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Ignoring Plex client owned by '%s'", session_username
|
"Ignoring %s client owned by '%s'",
|
||||||
|
player.product,
|
||||||
|
session_username,
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
self._known_idle.discard(player.machineIdentifier)
|
process_device("session", player)
|
||||||
available_clients.setdefault(
|
|
||||||
player.machineIdentifier, {"device": player}
|
|
||||||
)
|
|
||||||
available_clients[player.machineIdentifier]["session"] = session
|
available_clients[player.machineIdentifier]["session"] = session
|
||||||
|
|
||||||
if player.machineIdentifier not in self._known_clients:
|
|
||||||
new_clients.add(player.machineIdentifier)
|
|
||||||
_LOGGER.debug("New session: %s", player.machineIdentifier)
|
|
||||||
|
|
||||||
new_entity_configs = []
|
new_entity_configs = []
|
||||||
for client_id, client_data in available_clients.items():
|
for client_id, client_data in available_clients.items():
|
||||||
if client_id in ignored_clients:
|
if client_id in ignored_clients:
|
||||||
|
@ -93,7 +93,15 @@ async def test_new_ignored_users_available(hass, caplog):
|
|||||||
assert len(monitored_users) == 1
|
assert len(monitored_users) == 1
|
||||||
assert len(ignored_users) == 2
|
assert len(ignored_users) == 2
|
||||||
for ignored_user in ignored_users:
|
for ignored_user in ignored_users:
|
||||||
assert f"Ignoring Plex client owned by '{ignored_user}'" in caplog.text
|
ignored_client = [
|
||||||
|
x.players[0]
|
||||||
|
for x in mock_plex_server.sessions()
|
||||||
|
if x.usernames[0] in ignored_users
|
||||||
|
][0]
|
||||||
|
assert (
|
||||||
|
f"Ignoring {ignored_client.product} client owned by '{ignored_user}'"
|
||||||
|
in caplog.text
|
||||||
|
)
|
||||||
|
|
||||||
sensor = hass.states.get("sensor.plex_plex_server_1")
|
sensor = hass.states.get("sensor.plex_plex_server_1")
|
||||||
assert sensor.state == str(len(mock_plex_server.accounts))
|
assert sensor.state == str(len(mock_plex_server.accounts))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user