mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Improve foscam library exception support (#11701)
* Improve foscam library exception support Catches foscam exceptions that otherwise pollute the log. Many of these exception can safely be ignored * Fixed line length Fixed line length * Changed exception and log handling changed logging and catched only the TypeError effecting the library * Removed unused var Removed var * Fix remaining issue
This commit is contained in:
parent
0db9c04f21
commit
502ebd2a31
@ -44,6 +44,8 @@ class FoscamCam(Camera):
|
||||
|
||||
def __init__(self, device_info):
|
||||
"""Initialize a Foscam camera."""
|
||||
from libpyfoscam import FoscamCamera
|
||||
|
||||
super(FoscamCam, self).__init__()
|
||||
|
||||
ip_address = device_info.get(CONF_IP)
|
||||
@ -53,10 +55,8 @@ class FoscamCam(Camera):
|
||||
self._name = device_info.get(CONF_NAME)
|
||||
self._motion_status = False
|
||||
|
||||
from libpyfoscam import FoscamCamera
|
||||
|
||||
self._foscam_session = FoscamCamera(ip_address, port, self._username,
|
||||
self._password, verbose=False)
|
||||
self._foscam_session = FoscamCamera(
|
||||
ip_address, port, self._username, self._password, verbose=False)
|
||||
|
||||
def camera_image(self):
|
||||
"""Return a still image response from the camera."""
|
||||
@ -75,20 +75,20 @@ class FoscamCam(Camera):
|
||||
|
||||
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 = self._foscam_session.enable_motion_detection()
|
||||
self._motion_status = ret == FOSCAM_COMM_ERROR
|
||||
except TypeError:
|
||||
_LOGGER.debug("Communication problem")
|
||||
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 = self._foscam_session.disable_motion_detection()
|
||||
self._motion_status = ret == FOSCAM_COMM_ERROR
|
||||
except TypeError:
|
||||
_LOGGER.debug("Communication problem")
|
||||
self._motion_status = False
|
||||
|
||||
@property
|
||||
|
Loading…
x
Reference in New Issue
Block a user