diff --git a/homeassistant/components/camera/foscam.py b/homeassistant/components/camera/foscam.py index 3cc391eae33f5..15db83d345a93 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 @@ def __init__(self, device_info): 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 @@ 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 = 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