|
| 1 | +class ZoomAPIMixin: |
| 2 | + """ |
| 3 | + API for zooming and changing focus. |
| 4 | + Note that the API does not allow zooming/focusing by absolute |
| 5 | + values rather that changing focus/zoom for a given time. |
| 6 | + """ |
| 7 | + def _start_operation(self, operation, speed): |
| 8 | + data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": operation, "speed": speed}}] |
| 9 | + return self._execute_command('PtzCtrl', data) |
| 10 | + |
| 11 | + def _stop_zooming_or_focusing(self): |
| 12 | + """This command stops any ongoing zooming or focusing actions.""" |
| 13 | + data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": "Stop"}}] |
| 14 | + return self._execute_command('PtzCtrl', data) |
| 15 | + |
| 16 | + def start_zooming_in(self, speed=60): |
| 17 | + """ |
| 18 | + The camera zooms in until self.stop_zooming() is called. |
| 19 | + :return: response json |
| 20 | + """ |
| 21 | + return self._start_operation('ZoomInc', speed=speed) |
| 22 | + |
| 23 | + def start_zooming_out(self, speed=60): |
| 24 | + """ |
| 25 | + The camera zooms out until self.stop_zooming() is called. |
| 26 | + :return: response json |
| 27 | + """ |
| 28 | + return self._start_operation('ZoomDec', speed=speed) |
| 29 | + |
| 30 | + def stop_zooming(self): |
| 31 | + """ |
| 32 | + Stop zooming. |
| 33 | + :return: response json |
| 34 | + """ |
| 35 | + return self._stop_zooming_or_focusing() |
| 36 | + |
| 37 | + def start_focusing_in(self, speed=32): |
| 38 | + """ |
| 39 | + The camera focuses in until self.stop_focusing() is called. |
| 40 | + :return: response json |
| 41 | + """ |
| 42 | + return self._start_operation('FocusInc', speed=speed) |
| 43 | + |
| 44 | + def start_focusing_out(self, speed=32): |
| 45 | + """ |
| 46 | + The camera focuses out until self.stop_focusing() is called. |
| 47 | + :return: response json |
| 48 | + """ |
| 49 | + return self._start_operation('FocusDec', speed=speed) |
| 50 | + |
| 51 | + def stop_focusing(self): |
| 52 | + """ |
| 53 | + Stop focusing. |
| 54 | + :return: response json |
| 55 | + """ |
| 56 | + return self._stop_zooming_or_focusing() |
0 commit comments