Add config option to ignore Plex Web clients (#34708)

This commit is contained in:
jjlawren authored and GitHub committed 2020-05-08 09:49:15 -07:00
1 parent e56dd8ed50
commit ad419911bc
7 files changed
+78 -3

No files matched your search

@@ -30,6 +30,7 @@ from .const import ( # pylint: disable=unused-import
AUTOMATIC_SETUP_STRING,
CONF_CLIENT_IDENTIFIER,
CONF_IGNORE_NEW_SHARED_USERS,
CONF_IGNORE_PLEX_WEB_CLIENTS,
CONF_MONITORED_USERS,
CONF_SERVER,
CONF_SERVER_IDENTIFIER,
@@ -329,6 +330,9 @@ class PlexOptionsFlowHandler(config_entries.OptionsFlow):
self.options[MP_DOMAIN][CONF_IGNORE_NEW_SHARED_USERS] = user_input[
CONF_IGNORE_NEW_SHARED_USERS
]
self.options[MP_DOMAIN][CONF_IGNORE_PLEX_WEB_CLIENTS] = user_input[
CONF_IGNORE_PLEX_WEB_CLIENTS
]
account_data = {
user: {"enabled": bool(user in user_input[CONF_MONITORED_USERS])}
@@ -373,6 +377,10 @@ class PlexOptionsFlowHandler(config_entries.OptionsFlow):
CONF_IGNORE_NEW_SHARED_USERS,
default=plex_server.option_ignore_new_shared_users,
): bool,
vol.Required(
CONF_IGNORE_PLEX_WEB_CLIENTS,
default=plex_server.option_ignore_plexweb_clients,
): bool,
}
),
)
+1
View File
@@ -30,6 +30,7 @@ CONF_SERVER_IDENTIFIER = "server_id"
CONF_USE_EPISODE_ART = "use_episode_art"
CONF_SHOW_ALL_CONTROLS = "show_all_controls"
CONF_IGNORE_NEW_SHARED_USERS = "ignore_new_shared_users"
CONF_IGNORE_PLEX_WEB_CLIENTS = "ignore_plex_web_clients"
CONF_MONITORED_USERS = "monitored_users"
AUTH_CALLBACK_PATH = "/auth/plex/callback"
+25 -1
View File
@@ -19,6 +19,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
from .const import (
CONF_CLIENT_IDENTIFIER,
CONF_IGNORE_NEW_SHARED_USERS,
CONF_IGNORE_PLEX_WEB_CLIENTS,
CONF_MONITORED_USERS,
CONF_SERVER,
CONF_USE_EPISODE_ART,
@@ -50,6 +51,7 @@ class PlexServer:
"""Initialize a Plex server instance."""
self.hass = hass
self._plex_server = None
self._created_clients = set()
self._known_clients = set()
self._known_idle = set()
self._url = server_config.get(CONF_URL)
@@ -217,7 +219,23 @@ class PlexServer:
self._known_idle.discard(device.machineIdentifier)
available_clients.setdefault(device.machineIdentifier, {"device": device})
if device.machineIdentifier not in self._known_clients:
if device.machineIdentifier not in ignored_clients:
if self.option_ignore_plexweb_clients and device.product == "Plex Web":
ignored_clients.add(device.machineIdentifier)
if device.machineIdentifier not in self._known_clients:
_LOGGER.debug(
"Ignoring %s %s: %s",
"Plex Web",
source,
device.machineIdentifier,
)
return
if (
device.machineIdentifier not in self._created_clients
and device.machineIdentifier not in ignored_clients
and device.machineIdentifier not in new_clients
):
new_clients.add(device.machineIdentifier)
_LOGGER.debug(
"New %s %s: %s", device.product, source, device.machineIdentifier
@@ -250,6 +268,7 @@ class PlexServer:
continue
if client_id in new_clients:
new_entity_configs.append(client_data)
self._created_clients.add(client_id)
else:
self.async_refresh_entity(
client_id, client_data["device"], client_data.get("session")
@@ -327,6 +346,11 @@ class PlexServer:
"""Return dict of monitored users option."""
return self.options[MP_DOMAIN].get(CONF_MONITORED_USERS, {})
@property
def option_ignore_plexweb_clients(self):
"""Return ignore_plex_web_clients option."""
return self.options[MP_DOMAIN].get(CONF_IGNORE_PLEX_WEB_CLIENTS, False)
@property
def library(self):
"""Return library attribute from server object."""
+2 -1
View File
@@ -51,7 +51,8 @@
"data": {
"use_episode_art": "Use episode art",
"ignore_new_shared_users": "Ignore new managed/shared users",
"monitored_users": "Monitored users"
"monitored_users": "Monitored users",
"ignore_plex_web_clients": "Ignore Plex Web clients"
}
}
}