-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
Improve foscam library exception support #11701
Improve foscam library exception support #11701
Conversation
Catches foscam exceptions that otherwise pollute the log. Many of these exception can safely be ignored
Hi @i-am-shodan, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
else: | ||
self._motion_status = False | ||
except: | ||
_LOGGER.debug("An exception occured when communicating with the Foscam Camera") |
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.
line too long (91 > 79 characters)
try: | ||
ret, err = self._foscam_session.disable_motion_detection() | ||
if ret == FOSCAM_COMM_ERROR: | ||
_LOGGER.debug("Unable to communicate with Foscam Camera: %s", err) |
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.
line too long (82 > 79 characters)
else: | ||
self._motion_status = False | ||
except: | ||
_LOGGER.debug("An exception occured when communicating with the Foscam Camera") |
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.
line too long (91 > 79 characters)
try: | ||
ret, err = self._foscam_session.enable_motion_detection() | ||
if ret == FOSCAM_COMM_ERROR: | ||
_LOGGER.debug("Unable to communicate with Foscam Camera: %s", err) |
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.
line too long (82 > 79 characters)
Fixed line length
else: | ||
try: | ||
ret, err = self._foscam_session.enable_motion_detection() | ||
if ret == FOSCAM_COMM_ERROR: |
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.
This code makes no sense. If it is an error, log that an error has occurred and then assume the command was successful because we're setting the attribute to True
?
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.
If you loved this then you’ll love the constructor for this module. Who approved this in the first place???
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.
So if this is supposed to be the "positive" result, we should not log "Unable to communicate"? I know it is not your code, but if you're touching it, let's at least just remove that log statement.
self._motion_status = True | ||
else: | ||
self._motion_status = False | ||
except: |
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.
Please specify the exceptions that Foscam can raise
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.
Without having the broad range of Foscam devices to test against this isn’t really achievable to fix this bug. There are at least two cases noted in the upstream repo.
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.
You should be able to see what the Python classes are of the exceptions that get raised
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.
Looks like both the issues upstream result in TypeErrors. I'll add just those
self._motion_status = True | ||
else: | ||
try: | ||
ret, err = self._foscam_session.enable_motion_detection() |
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.
What's the use of returning an err
code if it can also throw exceptions 🤔
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.
A question to the original author perhaps. This patch is a sticking plaster to fix a long standing bug.
This whole module is a mess. The bigger question is why it raises an exception when the command actually works. The goal of this patch is not to save this module from itself but to fix long standing bugs in it. |
Oh I remember this lib now, it broke a release of ours. One day should indeed be replaced. |
changed logging and catched only the TypeError effecting the library
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.
Ok to merge when tests pass
I believe the author used the wrong email. I did not make this pull
request.
…On Fri, Jan 19, 2018 at 12:58 AM Paulus Schoutsen ***@***.***> wrote:
***@***.**** approved this pull request.
Ok to merge when tests pass
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11701 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFgEWvVanxO-RD5h62VhOR4rq7cSJHONks5tMC8JgaJpZM4RfuFP>
.
|
Removed var
Can we ignore the shorter if statement. It will result in a long line that hound will throw up |
Long line? This seems well below 80 chars: self._motion_status = ret == FOSCAM_COMM_ERROR |
If I was to implement the lint warning it would make the line over 80 chars. |
80 character length is pretty standard and not a required part of the pep standards but in any case that is what the project uses. baloob gave you a perfect answer to replace 4 lines of code with one nice short line. |
* upstream/master: (465 commits) Update pyhomematic to 0.1.38 (home-assistant#11936) Implement Alexa temperature sensors (home-assistant#11930) Fixed rfxtrx binary_sensor KeyError on missing optional device_class (home-assistant#11925) Allow setting climate devices to AUTO mode via Google Assistant (home-assistant#11923) fixes home-assistant#11848 (home-assistant#11915) Add "write" service to system_log (home-assistant#11901) Update frontend to 20180126.0 Version 0.62 Allow separate command and state OIDs and payloads in SNMP switch (home-assistant#11075) Add ERC20 tokens to etherscan.io sensor (home-assistant#11916) Report scripts and groups as scenes to Alexa (home-assistant#11900) Minor fix to configuration validation and related log line. (home-assistant#11898) Multi-Room Support for Greenwave Reality (home-assistant#11364) Added Xeoma camera platform (home-assistant#11619) Improve foscam library exception support (home-assistant#11701) Iota wallet (home-assistant#11398) New venstar climate component (home-assistant#11639) Update python-wink version and multiple wink fixes/updates. (home-assistant#11833) Use API to discover Hue if no bridges specified (home-assistant#11909) Clarify emulated hue warning (home-assistant#11910) ...
Catches foscam exceptions that otherwise pollute the log. Many of these exception can safely be ignored
Description:
The Python Foscam library correctly sets motion detection on my Foscam FI9800P but throws an exception while doing so. I've 'fixed' this by adding an exception handler/logging. This will then allow people to suppress the messages via an entry in their configuration.
The upstream maintainer of the Python Foscam library is AWOL and hasn't responded to the actual problem: quatanium/foscam-python-lib#22
In time Python Foscam should be replaced, it's pretty bad and doesn't support many devices.
Related issue (if applicable): fixes #9484
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>
Example entry for
configuration.yaml
(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices:
tox
run successfully. Your PR cannot be merged unless tests pass