Plex logging additions & cleanup (#33681)
parent
8d3a415d07
commit
d3a4270312
|
@ -159,6 +159,7 @@ class PlexServer:
|
|||
for account in self._plex_server.systemAccounts()
|
||||
if account.name
|
||||
]
|
||||
_LOGGER.debug("Linked accounts: %s", self.accounts)
|
||||
|
||||
owner_account = [
|
||||
account.name
|
||||
|
@ -167,6 +168,7 @@ class PlexServer:
|
|||
]
|
||||
if owner_account:
|
||||
self._owner_username = owner_account[0]
|
||||
_LOGGER.debug("Server owner found: '%s'", self._owner_username)
|
||||
|
||||
self._version = self._plex_server.version
|
||||
|
||||
|
@ -209,11 +211,11 @@ class PlexServer:
|
|||
try:
|
||||
devices = self._plex_server.clients()
|
||||
sessions = self._plex_server.sessions()
|
||||
except plexapi.exceptions.BadRequest:
|
||||
_LOGGER.exception("Error requesting Plex client data from server")
|
||||
return
|
||||
except requests.exceptions.RequestException as ex:
|
||||
_LOGGER.warning(
|
||||
except (
|
||||
plexapi.exceptions.BadRequest,
|
||||
requests.exceptions.RequestException,
|
||||
) as ex:
|
||||
_LOGGER.error(
|
||||
"Could not connect to Plex server: %s (%s)", self.friendly_name, ex
|
||||
)
|
||||
return
|
||||
|
@ -234,7 +236,9 @@ class PlexServer:
|
|||
for player in session.players:
|
||||
if session_username and session_username not in monitored_users:
|
||||
ignored_clients.add(player.machineIdentifier)
|
||||
_LOGGER.debug("Ignoring Plex client owned by %s", session_username)
|
||||
_LOGGER.debug(
|
||||
"Ignoring Plex client owned by '%s'", session_username
|
||||
)
|
||||
continue
|
||||
self._known_idle.discard(player.machineIdentifier)
|
||||
available_clients.setdefault(
|
||||
|
|
|
@ -116,24 +116,21 @@ async def test_setup_with_config_entry(hass, caplog):
|
|||
|
||||
await trigger_plex_update(hass, server_id)
|
||||
|
||||
with patch.object(
|
||||
mock_plex_server, "clients", side_effect=plexapi.exceptions.BadRequest
|
||||
) as patched_clients_bad_request:
|
||||
await trigger_plex_update(hass, server_id)
|
||||
for test_exception in (
|
||||
plexapi.exceptions.BadRequest,
|
||||
requests.exceptions.RequestException,
|
||||
):
|
||||
with patch.object(
|
||||
mock_plex_server, "clients", side_effect=test_exception
|
||||
) as patched_clients_bad_request:
|
||||
await trigger_plex_update(hass, server_id)
|
||||
|
||||
assert patched_clients_bad_request.called
|
||||
assert "Error requesting Plex client data from server" in caplog.text
|
||||
|
||||
with patch.object(
|
||||
mock_plex_server, "clients", side_effect=requests.exceptions.RequestException
|
||||
) as patched_clients_requests_exception:
|
||||
await trigger_plex_update(hass, server_id)
|
||||
|
||||
assert patched_clients_requests_exception.called
|
||||
assert (
|
||||
f"Could not connect to Plex server: {mock_plex_server.friendlyName}"
|
||||
in caplog.text
|
||||
)
|
||||
assert patched_clients_bad_request.called
|
||||
assert (
|
||||
f"Could not connect to Plex server: {mock_plex_server.friendlyName}"
|
||||
in caplog.text
|
||||
)
|
||||
caplog.clear()
|
||||
|
||||
|
||||
async def test_set_config_entry_unique_id(hass):
|
||||
|
|
|
@ -94,7 +94,7 @@ async def test_new_ignored_users_available(hass, caplog):
|
|||
assert len(monitored_users) == 1
|
||||
assert len(ignored_users) == 2
|
||||
for ignored_user in ignored_users:
|
||||
assert f"Ignoring Plex client owned by {ignored_user}" in caplog.text
|
||||
assert f"Ignoring Plex client owned by '{ignored_user}'" in caplog.text
|
||||
|
||||
sensor = hass.states.get("sensor.plex_plex_server_1")
|
||||
assert sensor.state == str(len(mock_plex_server.accounts))
|
||||
|
|
Loading…
Reference in New Issue