Make internal methods more generic

This commit is contained in:
Max Ziermann
2020-03-06 22:32:12 +01:00
parent 8506e3a294
commit 6506bf2cbc

View File

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