Skip to content

Commit

Permalink
Add new ptz & video commands
Browse files Browse the repository at this point in the history
Add ptz tour command. Add video_in_option & set_video_in_option for retrieving and setting video input parameters. Add video day_night_color & smart_ir properties and setters for Day profile.
  • Loading branch information
pnbruckner committed Mar 22, 2019
1 parent 31e6982 commit 3d0c79f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 9 deletions.
16 changes: 16 additions & 0 deletions src/amcrest/ptz.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,22 @@ def go_to_preset(self, action=None, channel=0, preset_point_number=1):
)
return ret.content.decode('utf-8')

def tour(self, action='start', channel=0, start=True, tour_path_number=1):
"""
Params:
action - start or stop
channel - channel number
start - True (StartTour) or False (StopTour)
tour_path_number - tour path number
"""
ret = self.command(
'ptz.cgi?action={0}&channel={1}&code={2}Tour&arg1={3}'
'&arg2=0&arg3=0&arg4=0'.format(
action, channel, 'Start' if start else 'Stop',
tour_path_number)
)
return ret.content.decode('utf-8')

def move_left_up(self, action=None, channel=0,
vertical_speed=1, horizontal_speed=1):
"""
Expand Down
66 changes: 57 additions & 9 deletions src/amcrest/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,62 @@ def video_in_options(self):
)
return ret.content.decode('utf-8')

def video_in_option(self, param, profile='Day'):
"""
Return video input option.
Params:
param - parameter, such as 'DayNightColor'
profile - 'Day', 'Night' or 'Normal'
"""
if profile == 'Day':
field = param
else:
field = '{}Options.{}'.format(profile, param)
return utils.pretty(
[opt for opt in self.video_in_options.split()
if '].{}='.format(field) in opt][0])

def set_video_in_option(self, param, value, profile='Day'):
if profile == 'Day':
field = param
else:
field = '{}Options.{}'.format(profile, param)
ret = self.command(
'configManager.cgi?action=setConfig'
'&VideoInOptions[0].{}={}'.format(field, value)
)
return ret.content.decode('utf-8')

@property
def day_night_color(self):
"""
Return Day & Night Color Mode for Day profile.
Result is 0: always multicolor
1: autoswitch along with brightness
2: always monochrome
"""
return int(self.video_in_option('DayNightColor'))

@day_night_color.setter
def day_night_color(self, value):
return self.set_video_in_option('DayNightColor', value)

@property
def smart_ir(self):
"""Return if SmartIR is on."""
return self.video_in_option('InfraRed') == 'false'

@smart_ir.setter
def smart_ir(self, value):
# It's not clear why from the HTTP API SDK doc, but setting InfraRed
# to false sets the Night Vision Mode to SmartIR, whereas setting it
# to true sets the Night Vision Mode to OFF. Night Vision Mode has a
# third setting of Manual, but that must be selected some other way
# via the HTTP API.
return self.set_video_in_option('InfraRed', str(not value).lower())

@property
def video_out_options(self):
ret = self.command(
Expand All @@ -143,13 +199,5 @@ def video_enabled(self):

@video_enabled.setter
def video_enabled(self, enable):
"""Enable/disable all video streams."""
self.command(utils.enable_audio_video_cmd('Video', enable))
# It's not clear why from the HTTP API SDK doc, but setting InfraRed
# to false sets the Night Vision Mode to SmartIR, whereas setting it
# to true sets the Night Vision Mode to OFF. Night Vision Mode has a
# third setting of Manual, but that must be selected some other way
# via the HTTP API.
self.command(
'configManager.cgi?action=setConfig'
'&VideoInOptions[0].InfraRed={}'.format(str(not enable).lower()))
self.smart_ir = enable

0 comments on commit 3d0c79f

Please sign in to comment.