From 502ebd2a311e1df2630527a22943f9dc8079a812 Mon Sep 17 00:00:00 2001 From: i-am-shodan <6901273+i-am-shodan@users.noreply.github.com> Date: Thu, 25 Jan 2018 22:47:53 +0000 Subject: [PATCH] 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 --- homeassistant/components/camera/foscam.py | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/camera/foscam.py b/homeassistant/components/camera/foscam.py index 3cc391eae33..15db83d345a 100644 --- a/homeassistant/components/camera/foscam.py +++ b/homeassistant/components/camera/foscam.py @@ -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