Bugfix: 10509 - http is hard coded in plex sensor#11072
Conversation
|
@balloob Cleaned up PR |
| plex_token = config.get(CONF_TOKEN) | ||
| plex_url = 'http://{}:{}'.format(plex_host, plex_port) | ||
| plex_ssl = config.get(CONF_SSL) | ||
| plex_verify_ssl = config.get(CONF_VERIFY_SSL) |
There was a problem hiding this comment.
Why is what needed?
There was a problem hiding this comment.
If you mean why am I assigning them to variables it's because the variables are used in the main Class as well as before it and having them as variables looks cleaner, in truth we could pass the whole of config into the main class and use the config options directly but I'm not sure it would be very clean looking.
There was a problem hiding this comment.
Why do we need to be able to disable SSL?
There was a problem hiding this comment.
Not everyone has it enabled for their local plex server
The issue this is to fix is that the uri was hardcoded as "http://" so no-one with ssl could use the sensor, this patch corrects that oversight.
In the case of the verify, it is also possible people are using self-signed certs (I think).
To be honest I dont use ssl for my local plex, I'm just doing this as it was raised as a bug.
There was a problem hiding this comment.
Okay, so that's SSL in the cloud. So I understand the SSL config var. I don't understand why we would ever allow disabling SSL verification?
There was a problem hiding this comment.
Basically the 3 use cases I can think of are:
- Self-Signed Certs
- proxy issues.
- Troubleshooting
It is NOT recommended and actively discouraged but better to have the option and not need it than need it and not be able to do it.
Side Note: Thanks for forcing me to clean up last PR, forced me to actually take some time to learn a bit more about GIT. :)
There was a problem hiding this comment.
We generally take a lot of care to limit the number of configuration options exposed to the user just to avoid confusion. Let's not preemptively add an option for something that's actively discouraged and breaks security. If they are using self-signed certs they need to properly configure their system to accept them.
There was a problem hiding this comment.
This option already is exposed in the plex media_player component, would it not be preferable to keep parity with the existing implementation within the same product?
Additionally this option is defaulted to True so most people will take the default option here, you would have to explicitly say "No don't check", which to me means you know what you are doing and why.
I dont use the SSL option for this anyway so i'm not particularly fussed, though I do think that where there is a chance someone will need an option we should expose it with a sensible default set. This way people can ignore it if its not applicable but equally if they need it it is there.
Corrected SSL Defaults to match the other Defaults style
|
This seems to work for me, except it doesn't read plex.conf like the media_player component does. FYI, the url of a plex server is and you can find the token using you can get the PLEXTOKEN doing https://forums.plex.tv/discussion/129922/how-to-request-a-x-plex-token-token-for-your-app |
|
No, it doesn't and it probably should, I'll add that as a feature update once this PR is approved. |
| """ | ||
| from datetime import timedelta | ||
| import logging | ||
| import requests |
|
@cnf can you please verify this still works? @armills @balloob Ok While I disagree with removing the option as we have it available in other components and I'd prefer to be consistent by making it easy to do the right thing (via sensible defaults) while still allowing those that wish to knowingly do the wrong thing to continue to work. I've removed the option to disable verification of the SSL Cert. |
emlove
left a comment
There was a problem hiding this comment.
Looks mostly good, just a small request on the new try. We'll also need a docs PR for the new config option.
| self._server = PlexServer(plex_url) | ||
|
|
||
| _LOGGER.info("Plex Sensor Configuration done") | ||
| except (plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized, |
There was a problem hiding this comment.
Move this try/except to surround the add_devices line in setup platform. Ignoring the exception here means we're creating the entity without a valid self._server, which the rest of the code doesn't handle.
| _LOGGER.info("Plex Sensor Configuration done") | ||
| except (plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized, | ||
| plexapi.exceptions.NotFound) as error: | ||
| _LOGGER.info(error) |
There was a problem hiding this comment.
If we can't recover from this exception this should be an error level log.
| from plexapi.myplex import MyPlexAccount | ||
| from plexapi.server import PlexServer | ||
|
|
||
| cert_session = None |
There was a problem hiding this comment.
It looks like this is always None. Can this be dropped?
| else: | ||
| self._server = PlexServer(plex_url) | ||
|
|
||
| _LOGGER.info("Plex Sensor Configuration done") |
There was a problem hiding this comment.
This log isn't necessary. Home assistant core will already log when each platform is setup.
| 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 \ |
There was a problem hiding this comment.
This line can go back as well now to clean up the diff.
|
@ryanm101 injecting https://github.com/ryanm101/home-assistant/blob/11079a2cc5d60271a091232104db6b80b04fa31c/homeassistant/components/sensor/plex.py into the docker container still works for me. |
|
Looks like it was just a flapping test. I restarted the job. |
emlove
left a comment
There was a problem hiding this comment.
Code is good, but marking this requested changes so we don't forget the docs update.
|
@armills That's already been done: |
|
Ah, thanks. Missed that. Next time if you can link the docs PR in the description it helps keep track of what's been done. |
|
Will do |
* Revert "Adding MotionIP to BinarySensors for HMIP-SMI (#11268)" This reverts commit c94cc34. * Revert "Bugfix: 10509 - http is hard coded in plex sensor (#11072)" This reverts commit 901d4b5. * Revert "Fix handling zero values for state_on/state_off (#11264)" This reverts commit 2e4e3a4. * Revert "Fix inverted sensors on the concord232 binary sensor component (#11261)" This reverts commit b866687. * Revert "Proper Steam game names and small fixes (#11182)" This reverts commit 7faa940. * Revert "Bugfix homematic available modus (#11256)" This reverts commit 1d57958. * Revert "Fix detection of if a negative node is in use (#11255)" This reverts commit b28bfad. * Revert "added myself to become code owner for miflora and plant (#11251)" This reverts commit e068204. * Revert "Add workaround for running tox on Windows platforms (#11188)" This reverts commit 81f1a65. * Revert "Upgrade to new miflora version 0.2.0 (#11250)" This reverts commit 8efc4b5. * Revert "homematic: add username and password to interface config schema (#11214)" This reverts commit b4e2537. * Revert "Backup configuration files before overwriting (#11216)" This reverts commit 90e25a6.
Fix for #10509