Skip to content

Commit 938009f

Browse files
authored
Merge pull request #210 from flacjacket/stream_set
Allow specifying stream to turn audio and video on or off
2 parents 03fe45d + 0d45c8b commit 938009f

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

src/amcrest/audio.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,22 @@ async def async_is_audio_enabled(
195195
)
196196
return is_enabled[channel]
197197

198-
def set_audio_enabled(self, enable: bool, *, channel: int = 0) -> None:
198+
def set_audio_enabled(
199+
self, enable: bool, *, channel: int = 0, stream: str = "Main"
200+
) -> None:
199201
"""Enable/disable all audio streams on given channel."""
200-
self.command(utils.enable_audio_video_cmd("Audio", enable, channel))
202+
self.command(
203+
utils.enable_audio_video_cmd(
204+
"Audio", enable, channel, stream=stream
205+
)
206+
)
201207

202208
async def async_set_audio_enabled(
203-
self, enable: bool, *, channel: int = 0
209+
self, enable: bool, *, channel: int = 0, stream: str = "Main"
204210
) -> None:
205211
"""Enable/disable all audio streams on given channel."""
206212
await self.async_command(
207-
utils.enable_audio_video_cmd("Audio", enable, channel)
213+
utils.enable_audio_video_cmd(
214+
"Audio", enable, channel, stream=stream
215+
)
208216
)

src/amcrest/http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ async def _async_command(
335335
follow_redirects=True,
336336
auth=self._async_token,
337337
verify=self._verify,
338-
timeout=httpx_timeout
338+
timeout=httpx_timeout,
339339
) as client:
340340
for loop in range(1, 2 + retries):
341341
_LOGGER.debug(
@@ -399,7 +399,7 @@ async def _async_stream_command(
399399
follow_redirects=True,
400400
auth=self._async_token,
401401
verify=self._verify,
402-
timeout=httpx_timeout
402+
timeout=httpx_timeout,
403403
) as client:
404404
async with client.stream("GET", url) as resp:
405405
try:

src/amcrest/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import re
1313
from datetime import datetime
14+
from typing import List
1415

1516
# pylint: disable=no-name-in-module
1617
from distutils import util
@@ -89,12 +90,19 @@ def extract_audio_video_enabled(param: str, resp: str) -> List[bool]:
8990
return parts
9091

9192

92-
def enable_audio_video_cmd(param: str, enable: bool, channel: int) -> str:
93+
def enable_audio_video_cmd(
94+
param: str, enable: bool, channel: int, *, stream: str
95+
) -> str:
9396
"""Return command to enable/disable all audio/video streams."""
9497
formats = [("Extra", 3), ("Main", 4)]
9598
if param == "Video":
9699
formats.append(("Snap", 3))
97100

101+
if stream is not None:
102+
formats = [x for x in formats if x[0] == stream]
103+
if not formats:
104+
raise RuntimeError(f"Bad stream specified: {stream}")
105+
98106
set_enable = str(enable).lower()
99107
cmds = ["configManager.cgi?action=setConfig"]
100108
cmds.extend(

src/amcrest/video.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,23 @@ async def async_is_video_enabled(
380380
)
381381
return is_enabled[channel]
382382

383-
def set_video_enabled(self, enable: bool, channel: int) -> None:
384-
self.command(utils.enable_audio_video_cmd("Video", enable, channel))
383+
def set_video_enabled(
384+
self, enable: bool, channel: int, *, stream: str = "Main"
385+
) -> None:
386+
self.command(
387+
utils.enable_audio_video_cmd(
388+
"Video", enable, channel, stream=stream
389+
)
390+
)
385391
self.set_smart_ir(enable, channel)
386392

387393
async def async_set_video_enabled(
388-
self, enable: bool, channel: int
394+
self, enable: bool, channel: int, *, stream: str = "Main"
389395
) -> None:
390396
await self.async_command(
391-
utils.enable_audio_video_cmd("Video", enable, channel)
397+
utils.enable_audio_video_cmd(
398+
"Video", enable, channel, stream=stream
399+
)
392400
)
393401
await self.async_set_smart_ir(enable, channel)
394402

0 commit comments

Comments
 (0)