-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Standardize Plex server connections #26444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MartinHjelmare
merged 22 commits into
home-assistant:dev
from
jjlawren:plex_central_server
Sep 5, 2019
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5da5030
Common connection class
jjlawren e4bb0ee
Omit tests for new Plex files
jjlawren 7dd2807
Oops
jjlawren 6cf083a
Add missing properties
jjlawren b3a7cf8
Remove redundant log message
jjlawren 5baca7c
Stopgap to avoid duplicate setups
jjlawren 6c44123
Merge branch 'dev' into plex_central_server
jjlawren cde3719
Cleaner check for server setup
jjlawren 75e819e
Cleaner check for server setup
jjlawren 2a03f95
Merge branch 'plex_central_server' of github.com:jjlawren/home-assist…
jjlawren 8f9c65d
Not needed with previous setup check
jjlawren 82b6d7a
Remove username/password support
jjlawren 1abc351
Reduce log level
jjlawren 9287b58
Don't do setup in __init__
jjlawren 370e70d
Oops
jjlawren e3952bf
Committing too fast...
jjlawren 16b2689
Connect after init
jjlawren 3b4a04d
Catch update exceptions like media_player
jjlawren 655e8fa
Pass in validated PlexServer instance
jjlawren 6fa8c0d
Remove unnecessary check
jjlawren 238c7a5
Counter should be unknown on init
jjlawren 3e741ae
Remove servername config option
jjlawren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| """Constants for the Plex component.""" | ||
| DOMAIN = "plex" | ||
| NAME_FORMAT = "Plex {}" | ||
|
|
||
| DEFAULT_PORT = 32400 | ||
| DEFAULT_SSL = False | ||
| DEFAULT_VERIFY_SSL = True | ||
|
|
||
| PLEX_CONFIG_FILE = "plex.conf" | ||
| PLEX_SERVER_CONFIG = "server_config" | ||
|
|
||
| CONF_USE_EPISODE_ART = "use_episode_art" | ||
| CONF_SHOW_ALL_CONTROLS = "show_all_controls" | ||
| CONF_REMOVE_UNAVAILABLE_CLIENTS = "remove_unavailable_clients" | ||
| CONF_CLIENT_REMOVE_INTERVAL = "client_remove_interval" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| """Shared class to maintain Plex server instances.""" | ||
| import logging | ||
| import plexapi.server | ||
| from requests import Session | ||
|
|
||
| from homeassistant.const import CONF_TOKEN, CONF_URL, CONF_VERIFY_SSL | ||
|
|
||
| from .const import DEFAULT_VERIFY_SSL | ||
|
|
||
| _LOGGER = logging.getLogger(__package__) | ||
|
|
||
|
|
||
| class PlexServer: | ||
| """Manages a single Plex server connection.""" | ||
|
|
||
| def __init__(self, server_config): | ||
| """Initialize a Plex server instance.""" | ||
| self._plex_server = None | ||
| self._url = server_config.get(CONF_URL) | ||
| self._token = server_config.get(CONF_TOKEN) | ||
| self._verify_ssl = server_config.get(CONF_VERIFY_SSL, DEFAULT_VERIFY_SSL) | ||
|
|
||
| def connect(self): | ||
| """Connect to a Plex server directly, obtaining direct URL if necessary.""" | ||
|
|
||
| def _connect_with_url(): | ||
|
MartinHjelmare marked this conversation as resolved.
|
||
| session = None | ||
| if self._url.startswith("https") and not self._verify_ssl: | ||
| session = Session() | ||
| session.verify = False | ||
| self._plex_server = plexapi.server.PlexServer( | ||
| self._url, self._token, session | ||
| ) | ||
| _LOGGER.debug("Connected to: %s (%s)", self.friendly_name, self.url_in_use) | ||
|
|
||
| _connect_with_url() | ||
|
|
||
| def clients(self): | ||
| """Pass through clients call to plexapi.""" | ||
| return self._plex_server.clients() | ||
|
|
||
| def sessions(self): | ||
| """Pass through sessions call to plexapi.""" | ||
| return self._plex_server.sessions() | ||
|
|
||
| @property | ||
| def friendly_name(self): | ||
| """Return name of connected Plex server.""" | ||
| return self._plex_server.friendlyName | ||
|
|
||
| @property | ||
| def machine_identifier(self): | ||
| """Return unique identifier of connected Plex server.""" | ||
| return self._plex_server.machineIdentifier | ||
|
|
||
| @property | ||
| def url_in_use(self): | ||
| """Return URL used for connected Plex server.""" | ||
| return self._plex_server._baseurl # pylint: disable=W0212 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.