-
-
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
Changes from 11 commits
fcd92f6
00f468d
032c527
19f1d85
17bbe0e
1905579
3c1ffb6
2cfa728
0a4e08e
92bfd05
f6bbf2c
c28ac78
bf87edb
11079a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,7 +51,9 @@ 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) | ||
|
|
||
| plex_url = '{}://{}:{}'.format('https' if config.get(CONF_SSL) else 'http', | ||
| plex_host, plex_port) | ||
|
|
||
| add_devices([PlexSensor( | ||
| name, plex_url, plex_user, plex_password, plex_server, | ||
|
|
@@ -63,19 +68,30 @@ def __init__(self, name, plex_url, plex_user, plex_password, | |
| """Initialize the sensor.""" | ||
| from plexapi.myplex import MyPlexAccount | ||
| from plexapi.server import PlexServer | ||
| import plexapi.exceptions | ||
|
|
||
| cert_session = None | ||
|
|
||
| self._name = name | ||
| self._state = 0 | ||
| self._now_playing = [] | ||
|
|
||
| if plex_token: | ||
| self._server = PlexServer(plex_url, plex_token) | ||
| elif plex_user and plex_password: | ||
| user = MyPlexAccount(plex_user, plex_password) | ||
| server = plex_server if plex_server else user.resources()[0].name | ||
| self._server = user.resource(server).connect() | ||
| else: | ||
| self._server = PlexServer(plex_url) | ||
| try: | ||
| if 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 | ||
| self._server = user.resource(server).connect() | ||
| else: | ||
| self._server = PlexServer(plex_url) | ||
|
|
||
| _LOGGER.info("Plex Sensor Configuration done") | ||
| except (plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized, | ||
|
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. Move this try/except to surround the
Contributor
Author
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. done |
||
| plexapi.exceptions.NotFound) as error: | ||
| _LOGGER.info(error) | ||
|
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. If we can't recover from this exception this should be an error level log.
Contributor
Author
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. done |
||
| return | ||
|
|
||
| @property | ||
| def name(self): | ||
|
|
||
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?