YACWC
This commit is contained in:
@@ -12,3 +12,7 @@ class AlarmAPIMixin:
|
||||
"""
|
||||
body = [{"cmd": "GetAlarm", "action": 1, "param": {"Alarm": {"channel": 0, "type": "md"}}}]
|
||||
return self._execute_command('GetAlarm', body)
|
||||
|
||||
def get_ai_state(self) -> Dict:
|
||||
body = [{"cmd": "GetAIState"}]
|
||||
return self._execute_command('GetAlarm', body)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from typing import Dict
|
||||
|
||||
import time
|
||||
|
||||
class PtzAPIMixin:
|
||||
"""
|
||||
@@ -121,3 +121,65 @@ class PtzAPIMixin:
|
||||
:return: response json
|
||||
"""
|
||||
return self._send_operation('Auto', speed=speed)
|
||||
|
||||
def get_zoom_focus_pos(self) -> Dict:
|
||||
body = [{"cmd": "GetZoomFocus", "action": 0, "param": {'channel':0}}]
|
||||
return self._execute_command('GetZoomFocus',body)
|
||||
|
||||
def set_auto_focus_state(self, state: bool = True) -> Dict:
|
||||
body = [{"cmd": "SetAutoFocus", "action": 0, "param": {'AutoFocus':{'channel':0,'disable':int(state)}}}]
|
||||
return self._execute_command('SetAutoFocus',body)
|
||||
|
||||
def get_auto_focus_state(self) -> bool:
|
||||
body = [{"cmd": "GetAutoFocus", "action": 1, "param": {'channel':0}}]
|
||||
return bool(self._execute_command('GetAutoFocus',body)[0]['value']['AutoFocus']['disable'])
|
||||
|
||||
|
||||
def set_zoom_pos(self, pos: int) -> Dict:
|
||||
body = [{"cmd": "StartZoomFocus", "action": 0, "param": {'ZoomFocus':{'channel':0,'pos':pos,'op':'ZoomPos'}}}]
|
||||
self._execute_command('StartZoomFocus',body)
|
||||
|
||||
|
||||
def set_focus_pos(self, pos: int) -> Dict:
|
||||
body = [{"cmd": "StartZoomFocus", "action": 0, "param": {'ZoomFocus':{'channel':0,'pos':pos,'op':'FocusPos'}}}]
|
||||
self._execute_command('StartZoomFocus',body)
|
||||
|
||||
|
||||
def generic_set_block(self, pos:int, get_func, set_func) -> int:
|
||||
|
||||
|
||||
change_index = 0
|
||||
last_pos = get_func()
|
||||
pos = min([pos,254])
|
||||
pos = max([pos, 0])
|
||||
|
||||
target_pos = pos
|
||||
set_func(pos)
|
||||
for i in range(100):
|
||||
cpos = get_func()
|
||||
if cpos != last_pos:
|
||||
change_index = i
|
||||
|
||||
if cpos == target_pos:
|
||||
break
|
||||
|
||||
|
||||
if (i - change_index) > 8:
|
||||
break
|
||||
|
||||
last_pos = cpos
|
||||
time.sleep(0.25)
|
||||
|
||||
return cpos
|
||||
|
||||
def set_focus_pos_block(self, pos: int) -> int:
|
||||
return self.generic_set_block(pos, self.get_focus_pos, self.set_focus_pos)
|
||||
|
||||
def set_zoom_pos_block(self, pos: int) -> int:
|
||||
return self.generic_set_block(pos, self.get_zoom_pos, self.set_zoom_pos)
|
||||
|
||||
def get_zoom_pos(self) -> int:
|
||||
return self.get_zoom_focus_pos()[0]['value']['ZoomFocus']['zoom']['pos']
|
||||
|
||||
def get_focus_pos(self) -> int:
|
||||
return self.get_zoom_focus_pos()[0]['value']['ZoomFocus']['focus']['pos']
|
||||
|
||||
Reference in New Issue
Block a user