Add zoom commands

This commit is contained in:
Max Ziermann
2020-03-04 13:48:44 +01:00
parent da46f0efca
commit 8506e3a294
3 changed files with 37 additions and 3 deletions

32
api/zoom.py Normal file
View File

@@ -0,0 +1,32 @@
class ZoomAPIMixin:
"""
API for zooming and changing focus.
Note that the API does not allow zooming/focusing by absolute
values rather that changing focus/zoom for a given time.
"""
def _start_zoom(self, direction, speed=60):
op = 'ZoomInc' if direction == 'in' else 'ZoomDec'
data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": op, "speed": speed}}]
return self._execute_command('PtzCtrl', data)
def start_zoom_in(self, speed=60):
"""
The camera zooms in until self.stop_zoom() is called.
:return: response json
"""
return self._start_zoom('in', speed=speed)
def start_zoom_out(self, speed=60):
"""
The camera zooms out until self.stop_zoom() is called.
:return: response json
"""
return self._start_zoom('out', speed=speed)
def stop_zoom(self):
"""
Stop zooming.
:return: response json
"""
data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": "Stop"}}]
return self._execute_command('PtzCtrl', data)