Add options to ignore shared/managed Plex clients (#31738)
* Add option to ignore shared/managed Plex clients * Start to allow user selection * hass object not ready during init * Don't bother sorting * Plex account multi-select, handle new users not matching config * Fix/add tests * Lint simplifications * Review cleanup * Oops * Rename options attributes, fix/add tests
This commit is contained in:
1 parent
4b3f9ecc2d
commit
0213f43f10
8 files changed
+272
-14
No files matched your search
@@ -1,4 +1,6 @@
|
||||
"""Mock classes used in tests."""
|
||||
import itertools
|
||||
|
||||
from homeassistant.components.plex.const import CONF_SERVER, CONF_SERVER_IDENTIFIER
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
|
||||
@@ -17,6 +19,12 @@ MOCK_SERVERS = [
|
||||
},
|
||||
]
|
||||
|
||||
MOCK_MONITORED_USERS = {
|
||||
"a": {"enabled": True},
|
||||
"b": {"enabled": False},
|
||||
"c": {"enabled": True},
|
||||
}
|
||||
|
||||
|
||||
class MockResource:
|
||||
"""Mock a PlexAccount resource."""
|
||||
@@ -65,7 +73,14 @@ class MockPlexSystemAccount:
|
||||
class MockPlexServer:
|
||||
"""Mock a PlexServer instance."""
|
||||
|
||||
def __init__(self, index=0, ssl=True):
|
||||
def __init__(
|
||||
self,
|
||||
index=0,
|
||||
ssl=True,
|
||||
load_users=True,
|
||||
num_users=len(MOCK_MONITORED_USERS),
|
||||
ignore_new_users=False,
|
||||
):
|
||||
"""Initialize the object."""
|
||||
host = MOCK_SERVERS[index][CONF_HOST]
|
||||
port = MOCK_SERVERS[index][CONF_PORT]
|
||||
@@ -78,11 +93,24 @@ class MockPlexServer:
|
||||
prefix = "https" if ssl else "http"
|
||||
self._baseurl = f"{prefix}://{host}:{port}"
|
||||
self._systemAccount = MockPlexSystemAccount()
|
||||
self._ignore_new_users = ignore_new_users
|
||||
self._load_users = load_users
|
||||
self._num_users = num_users
|
||||
|
||||
def systemAccounts(self):
|
||||
"""Mock the systemAccounts lookup method."""
|
||||
return [self._systemAccount]
|
||||
|
||||
@property
|
||||
def accounts(self):
|
||||
"""Mock the accounts property."""
|
||||
return set(["a", "b", "c"])
|
||||
|
||||
@property
|
||||
def owner(self):
|
||||
"""Mock the owner property."""
|
||||
return "a"
|
||||
|
||||
@property
|
||||
def url_in_use(self):
|
||||
"""Return URL used by PlexServer."""
|
||||
@@ -92,3 +120,24 @@ class MockPlexServer:
|
||||
def version(self):
|
||||
"""Mock version of PlexServer."""
|
||||
return "1.0"
|
||||
|
||||
@property
|
||||
def option_monitored_users(self):
|
||||
"""Mock loaded config option for monitored users."""
|
||||
userdict = dict(itertools.islice(MOCK_MONITORED_USERS.items(), self._num_users))
|
||||
return userdict if self._load_users else {}
|
||||
|
||||
@property
|
||||
def option_ignore_new_shared_users(self):
|
||||
"""Mock loaded config option for ignoring new users."""
|
||||
return self._ignore_new_users
|
||||
|
||||
@property
|
||||
def option_show_all_controls(self):
|
||||
"""Mock loaded config option for showing all controls."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def option_use_episode_art(self):
|
||||
"""Mock loaded config option for using episode art."""
|
||||
return False
|
||||
Reference in new issue
Block a user