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
pull/10397/merge
Andreas Björshammar 2018-01-12 00:44:23 +01:00 committed by Paulus Schoutsen
parent 2224d05607
commit 965bd8a2e0
1 changed files with 30 additions and 0 deletions

View File

@ -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)