-
-
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
Changes from 1 commit
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 |
---|---|---|
|
@@ -75,20 +75,28 @@ def motion_detection_enabled(self): | |
|
||
def enable_motion_detection(self): | ||
"""Enable motion detection in camera.""" | ||
ret, err = self._foscam_session.enable_motion_detection() | ||
if ret == FOSCAM_COMM_ERROR: | ||
_LOGGER.debug("Unable to communicate with Foscam Camera: %s", err) | ||
self._motion_status = True | ||
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 commentThe 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 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 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 commentThe 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. |
||
_LOGGER.debug("Unable to communicate with Foscam Camera: %s", err) | ||
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. line too long (82 > 79 characters) |
||
self._motion_status = True | ||
else: | ||
self._motion_status = False | ||
except: | ||
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. Please specify the exceptions that Foscam can raise 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. 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 commentThe 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 commentThe 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 |
||
_LOGGER.debug("An exception occured when communicating with the Foscam Camera") | ||
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. line too long (91 > 79 characters) |
||
self._motion_status = False | ||
|
||
def disable_motion_detection(self): | ||
"""Disable motion detection.""" | ||
ret, err = self._foscam_session.disable_motion_detection() | ||
if ret == FOSCAM_COMM_ERROR: | ||
_LOGGER.debug("Unable to communicate with Foscam Camera: %s", err) | ||
self._motion_status = True | ||
else: | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. line too long (82 > 79 characters) |
||
self._motion_status = True | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. line too long (91 > 79 characters) |
||
self._motion_status = False | ||
|
||
@property | ||
|
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.