mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Handle config with a limited Plex account (#35218)
This commit is contained in:
parent
64ce8e970f
commit
dfe2a457c0
@ -3,6 +3,7 @@ import logging
|
|||||||
import ssl
|
import ssl
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from plexapi.exceptions import Unauthorized
|
||||||
import plexapi.myplex
|
import plexapi.myplex
|
||||||
import plexapi.playqueue
|
import plexapi.playqueue
|
||||||
import plexapi.server
|
import plexapi.server
|
||||||
@ -138,21 +139,24 @@ class PlexServer:
|
|||||||
else:
|
else:
|
||||||
_connect_with_token()
|
_connect_with_token()
|
||||||
|
|
||||||
self._accounts = [
|
try:
|
||||||
account.name
|
system_accounts = self._plex_server.systemAccounts()
|
||||||
for account in self._plex_server.systemAccounts()
|
except Unauthorized:
|
||||||
if account.name
|
_LOGGER.warning(
|
||||||
]
|
"Plex account has limited permissions, shared account filtering will not be available."
|
||||||
_LOGGER.debug("Linked accounts: %s", self.accounts)
|
)
|
||||||
|
else:
|
||||||
|
self._accounts = [
|
||||||
|
account.name for account in system_accounts if account.name
|
||||||
|
]
|
||||||
|
_LOGGER.debug("Linked accounts: %s", self.accounts)
|
||||||
|
|
||||||
owner_account = [
|
owner_account = [
|
||||||
account.name
|
account.name for account in system_accounts if account.accountID == 1
|
||||||
for account in self._plex_server.systemAccounts()
|
]
|
||||||
if account.accountID == 1
|
if owner_account:
|
||||||
]
|
self._owner_username = owner_account[0]
|
||||||
if owner_account:
|
_LOGGER.debug("Server owner found: '%s'", self._owner_username)
|
||||||
self._owner_username = owner_account[0]
|
|
||||||
_LOGGER.debug("Server owner found: '%s'", self._owner_username)
|
|
||||||
|
|
||||||
self._version = self._plex_server.version
|
self._version = self._plex_server.version
|
||||||
|
|
||||||
|
@ -688,3 +688,36 @@ async def test_manual_config_with_token(hass):
|
|||||||
assert result["data"][CONF_SERVER_IDENTIFIER] == mock_plex_server.machineIdentifier
|
assert result["data"][CONF_SERVER_IDENTIFIER] == mock_plex_server.machineIdentifier
|
||||||
assert result["data"][PLEX_SERVER_CONFIG][CONF_URL] == mock_plex_server._baseurl
|
assert result["data"][PLEX_SERVER_CONFIG][CONF_URL] == mock_plex_server._baseurl
|
||||||
assert result["data"][PLEX_SERVER_CONFIG][CONF_TOKEN] == MOCK_TOKEN
|
assert result["data"][PLEX_SERVER_CONFIG][CONF_TOKEN] == MOCK_TOKEN
|
||||||
|
|
||||||
|
|
||||||
|
async def test_setup_with_limited_credentials(hass):
|
||||||
|
"""Test setup with a user with limited permissions."""
|
||||||
|
mock_plex_server = MockPlexServer()
|
||||||
|
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data=DEFAULT_DATA,
|
||||||
|
options=DEFAULT_OPTIONS,
|
||||||
|
unique_id=DEFAULT_DATA["server_id"],
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"plexapi.server.PlexServer", return_value=mock_plex_server
|
||||||
|
), patch.object(
|
||||||
|
mock_plex_server, "systemAccounts", side_effect=plexapi.exceptions.Unauthorized
|
||||||
|
) as mock_accounts, patch(
|
||||||
|
"homeassistant.components.plex.PlexWebsocket.listen"
|
||||||
|
) as mock_listen:
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert mock_listen.called
|
||||||
|
assert mock_accounts.called
|
||||||
|
|
||||||
|
plex_server = hass.data[DOMAIN][SERVERS][mock_plex_server.machineIdentifier]
|
||||||
|
assert len(plex_server.accounts) == 0
|
||||||
|
assert plex_server.owner is None
|
||||||
|
|
||||||
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
assert entry.state == ENTRY_STATE_LOADED
|
||||||
|
Loading…
x
Reference in New Issue
Block a user