Skip to content

Commit 396a856

Browse files
mheyenlkiesow
authored andcommitted
added automatic camera activation before updating position to start cameras in standby
1 parent 65ea84a commit 396a856

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

occameracontrol/camera.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,36 @@ def __str__(self) -> str:
7474
'''
7575
return f"'{self.agent.agent_id}' @ '{self.url}'"
7676

77+
def activate_camera(self, on=True):
78+
"""Activate the camera or put it into standby mode.
79+
parameters:
80+
on: bool - True to activate the camera, False to deactivate it. default is True.
81+
"""
82+
if self.type == CameraType.panasonic:
83+
url = f'{self.url}/cgi-bin/aw_ptz'
84+
command = '#On' if on else '#Of'
85+
params = {'cmd': command, 'res': 1}
86+
auth = (self.user, self.password) \
87+
if self.user and self.password else None
88+
logger.debug('GET %s with params: %s', url, params)
89+
response = requests.get(url, auth=auth, params=params, timeout=5)
90+
response.raise_for_status()
91+
92+
elif self.type == CameraType.sony:
93+
url = f'{self.url}/command/main.cgi'
94+
command = 'on' if on else 'standby'
95+
params = {'System': command}
96+
headers = {'referer': f'{self.url}/'}
97+
auth = HTTPDigestAuth(self.user, self.password) \
98+
if self.user and self.password else None
99+
logger.debug('GET %s with params: %s', url, params)
100+
response = requests.get(url,
101+
auth=auth,
102+
headers=headers,
103+
params=params,
104+
timeout=5)
105+
response.raise_for_status()
106+
77107
def move_to_preset(self, preset: int):
78108
'''Move the PTZ camera to the specified preset position
79109
'''
@@ -139,14 +169,17 @@ def update_position(self):
139169
logger.info('[%s] Event `%s` started', agent_id, event.title)
140170
logger.info('[%s] Moving to preset %i', agent_id,
141171
self.preset_active)
172+
self.activate_camera()
142173
self.move_to_preset(self.preset_active)
143174
else: # No active event
144175
if self.position != self.preset_inactive:
145176
logger.info('[%s] Returning to preset %i', agent_id,
146177
self.preset_inactive)
178+
self.activate_camera()
147179
self.move_to_preset(self.preset_inactive)
148180

149181
if time.time() - self.last_updated >= self.update_frequency:
150182
logger.info('[%s] Re-sending preset %i to camera', agent_id,
151183
self.position)
184+
self.activate_camera()
152185
self.move_to_preset(self.position)

0 commit comments

Comments
 (0)