From 965bd8a2e06a67753d79e751229ec6d4fc681daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Bj=C3=B6rshammar?= Date: Fri, 12 Jan 2018 00:44:23 +0100 Subject: [PATCH] Added support for enable/disable motion detection (#11583) * Added support for enable/disable motion detection * Changed name of variable for exception, lint error * Moved motion_detection_enabled property to the other properties --- homeassistant/components/camera/uvc.py | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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)