From 6506bf2cbcf3d1c2243361a935647231b7207798 Mon Sep 17 00:00:00 2001 From: Max Ziermann Date: Fri, 6 Mar 2020 22:32:12 +0100 Subject: [PATCH] Make internal methods more generic --- api/zoom.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/api/zoom.py b/api/zoom.py index a3e2097..2ae766c 100644 --- a/api/zoom.py +++ b/api/zoom.py @@ -4,29 +4,32 @@ class ZoomAPIMixin: 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}}] + def _start_operation(self, operation, speed): + data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": operation, "speed": speed}}] 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 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 self._start_zoom('out', speed=speed) + return self._start_operation('ZoomDec', speed=speed) - def stop_zoom(self): + def stop_zooming(self): """ Stop zooming. :return: response json """ - data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": "Stop"}}] - return self._execute_command('PtzCtrl', data) + return self._stop_zooming_or_focusing()