Plex logging additions & cleanup (#33681)

pull/33447/head
jjlawren 2020-04-05 01:21:20 -05:00 committed by GitHub
parent 8d3a415d07
commit d3a4270312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 24 deletions

View File

@ -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(

View File

@ -116,24 +116,21 @@ async def test_setup_with_config_entry(hass, caplog):
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=plexapi.exceptions.BadRequest
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
)
caplog.clear()
async def test_set_config_entry_unique_id(hass):

View File

@ -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))