diff --git a/homeassistant/components/camera/uvc.py b/homeassistant/components/camera/uvc.py index 685b6d64364..8d79fa04a9a 100644 --- a/homeassistant/components/camera/uvc.py +++ b/homeassistant/components/camera/uvc.py @@ -82,6 +82,7 @@ class UnifiVideoCamera(Camera): self.is_streaming = False self._connect_addr = None self._camera = None + self._motion_status = False @property def name(self): @@ -94,6 +95,12 @@ class UnifiVideoCamera(Camera): caminfo = self._nvr.get_camera(self._uuid) return caminfo['recordingSettings']['fullTimeRecordEnabled'] + @property + def motion_detection_enabled(self): + """Camera Motion Detection Status.""" + caminfo = self._nvr.get_camera(self._uuid) + return caminfo['recordingSettings']['motionRecordEnabled'] + @property def brand(self): """Return the brand of this camera.""" @@ -165,3 +172,26 @@ class UnifiVideoCamera(Camera): raise return _get_image() + + def set_motion_detection(self, mode): + """Set motion detection on or off.""" + from uvcclient.nvr import NvrError + if mode is True: + set_mode = 'motion' + else: + set_mode = 'none' + + try: + self._nvr.set_recordmode(self._uuid, set_mode) + self._motion_status = mode + except NvrError as err: + _LOGGER.error("Unable to set recordmode to " + set_mode) + _LOGGER.debug(err) + + def enable_motion_detection(self): + """Enable motion detection in camera.""" + self.set_motion_detection(True) + + def disable_motion_detection(self): + """Disable motion detection in camera.""" + self.set_motion_detection(False)