-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Bugfix: 10509 - http is hard coded in plex sensor #11072
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
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fcd92f6
Fix for sensor no ssl
ryanm101 00f468d
Line length Fixes
ryanm101 032c527
Removed unneeded schema extensions
ryanm101 19f1d85
Removed unrequired variable
ryanm101 17bbe0e
Added defaults for SSL & SSL Verify
ryanm101 1905579
Moved Defaults to Variables
ryanm101 3c1ffb6
Fixed Typo
ryanm101 2cfa728
Removed option to disable verify ssl
ryanm101 0a4e08e
Merge branch 'clean_plex_uri_fix' of github.com:ryanm101/home-assista…
ryanm101 92bfd05
Removed unused import
ryanm101 f6bbf2c
Removed unused CONST
ryanm101 c28ac78
Fixed error handling
ryanm101 bf87edb
Cleanup of unneeded vars & logging
ryanm101 11079a2
Fix for linting
ryanm101 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,8 @@ | |
|
|
||
| from homeassistant.components.switch import PLATFORM_SCHEMA | ||
| from homeassistant.const import ( | ||
| CONF_NAME, CONF_USERNAME, CONF_PASSWORD, CONF_HOST, CONF_PORT, CONF_TOKEN) | ||
| CONF_NAME, CONF_USERNAME, CONF_PASSWORD, CONF_HOST, CONF_PORT, CONF_TOKEN, | ||
| CONF_SSL) | ||
| from homeassistant.helpers.entity import Entity | ||
| from homeassistant.util import Throttle | ||
| import homeassistant.helpers.config_validation as cv | ||
|
|
@@ -24,6 +25,7 @@ | |
| DEFAULT_HOST = 'localhost' | ||
| DEFAULT_NAME = 'Plex' | ||
| DEFAULT_PORT = 32400 | ||
| DEFAULT_SSL = False | ||
|
|
||
| MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1) | ||
|
|
||
|
|
@@ -35,6 +37,7 @@ | |
| vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, | ||
| vol.Optional(CONF_SERVER): cv.string, | ||
| vol.Optional(CONF_USERNAME): cv.string, | ||
| vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean, | ||
| }) | ||
|
|
||
|
|
||
|
|
@@ -48,12 +51,20 @@ def setup_platform(hass, config, add_devices, discovery_info=None): | |
| plex_host = config.get(CONF_HOST) | ||
| plex_port = config.get(CONF_PORT) | ||
| plex_token = config.get(CONF_TOKEN) | ||
| plex_url = 'http://{}:{}'.format(plex_host, plex_port) | ||
|
|
||
| add_devices([PlexSensor( | ||
| name, plex_url, plex_user, plex_password, plex_server, | ||
| plex_token)], True) | ||
| plex_url = '{}://{}:{}'.format('https' if config.get(CONF_SSL) else 'http', | ||
| plex_host, plex_port) | ||
|
|
||
| import plexapi.exceptions | ||
|
|
||
| try: | ||
| add_devices([PlexSensor( | ||
| name, plex_url, plex_user, plex_password, plex_server, | ||
| plex_token)], True) | ||
| except (plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized, | ||
| plexapi.exceptions.NotFound) as error: | ||
| _LOGGER.error(error) | ||
| return | ||
|
|
||
| class PlexSensor(Entity): | ||
| """Representation of a Plex now playing sensor.""" | ||
|
|
@@ -64,19 +75,24 @@ def __init__(self, name, plex_url, plex_user, plex_password, | |
| from plexapi.myplex import MyPlexAccount | ||
| from plexapi.server import PlexServer | ||
|
|
||
| cert_session = None | ||
|
|
||
| self._name = name | ||
| self._state = 0 | ||
| self._now_playing = [] | ||
|
|
||
| if plex_token: | ||
| self._server = PlexServer(plex_url, plex_token) | ||
| self._server = PlexServer(plex_url, plex_token, cert_session) | ||
| elif plex_user and plex_password: | ||
| user = MyPlexAccount(plex_user, plex_password) | ||
| server = plex_server if plex_server else user.resources()[0].name | ||
| server = plex_server if plex_server \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line can go back as well now to clean up the diff. |
||
| else user.resources()[0].name | ||
| self._server = user.resource(server).connect() | ||
| else: | ||
| self._server = PlexServer(plex_url) | ||
|
|
||
| _LOGGER.info("Plex Sensor Configuration done") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This log isn't necessary. Home assistant core will already log when each platform is setup. |
||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of the sensor.""" | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is always
None. Can this be dropped?