Skip to content

Commit

Permalink
Merge pull request #193 from flacjacket/async
Browse files Browse the repository at this point in the history
Add async APIs throughout
  • Loading branch information
flacjacket authored Sep 16, 2021
2 parents 52f91d3 + ec22129 commit 180f1ea
Show file tree
Hide file tree
Showing 20 changed files with 1,640 additions and 305 deletions.
2 changes: 1 addition & 1 deletion cli/amcrest-cli
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def main():
camera.go_to_preset(channel=channel, preset_point_number=preset_point_number)

elif args.log_clear_all:
print(camera.log_clear_all)
print(camera.log_clear_all())

elif args.video_standard == -1:
print(camera.video_standard)
Expand Down
9 changes: 7 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ norecursedirs = .git
max-line-length = 79

[mypy]
python_version = 3.6
python_version = 3.7
disallow_subclassing_any = True
no_implicit_optional = True
show_error_codes = True
strict_equality = True
warn_incomplete_stub = True
warn_redundant_casts = True
warn_unreachable = True
warn_unused_configs = True
warn_unused_ignores = True
warn_unreachable = True
[mypy-urllib3.*]
ignore_missing_imports = True
60 changes: 33 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,39 @@


def readme():
with open('README.rst') as desc:
with open("README.rst") as desc:
return desc.read()


setup(name='amcrest',
version='1.8.1',
description='Python wrapper implementation for Amcrest cameras.',
long_description=readme(),
author='Douglas Schilling Landgraf, Marcelo Moreira de Mello',
author_email='[email protected], [email protected]',
url='http://github.com/tchellomello/python-amcrest',
license='GPLv2',
install_requires=[
'argcomplete', 'requests', 'typing_extensions', 'urllib3'
],
package_dir={'': 'src'},
packages=find_packages('src'),
include_package_data=True,
package_data={"amcrest": ["py.typed"]},
test_suite='tests',
scripts=['cli/amcrest-cli', 'tui/amcrest-tui'],
zip_safe=True,
keywords="amcrest camera python",
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
])
setup(
name="amcrest",
version="1.8.1",
description="Python wrapper implementation for Amcrest cameras.",
long_description=readme(),
author="Douglas Schilling Landgraf, Marcelo Moreira de Mello",
author_email="[email protected], [email protected]",
url="http://github.com/tchellomello/python-amcrest",
license="GPLv2",
install_requires=[
"argcomplete",
"httpx",
"requests",
"typing_extensions",
"urllib3",
],
package_dir={"": "src"},
packages=find_packages("src"),
include_package_data=True,
package_data={"amcrest": ["py.typed"]},
test_suite="tests",
scripts=["cli/amcrest-cli", "tui/amcrest-tui"],
zip_safe=True,
keywords="amcrest camera python",
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
)
51 changes: 42 additions & 9 deletions src/amcrest/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ def audio_input_channels_numbers(self) -> str:
ret = self.command("devAudioInput.cgi?action=getCollect")
return ret.content.decode()

@property
async def async_audio_input_channels_numbers(self) -> str:
ret = await self.async_command("devAudioInput.cgi?action=getCollect")
return ret.content.decode()

@property
def audio_output_channels_numbers(self) -> str:
ret = self.command("devAudioOutput.cgi?action=getCollect")
return ret.content.decode()

@property
async def async_audio_output_channels_numbers(self) -> str:
ret = await self.async_command("devAudioOutput.cgi?action=getCollect")
return ret.content.decode()

def play_wav(
self,
httptype: Optional[str] = None,
Expand Down Expand Up @@ -141,6 +151,21 @@ def audio_stream_capture(

return ret.raw

@property
def audio_enabled(self) -> bool:
"""Return if any audio stream enabled."""
return self.is_audio_enabled()

@audio_enabled.setter
def audio_enabled(self, enable: bool) -> None:
"""Enable/disable all audio streams."""
self.set_audio_enabled(enable)

@property
async def async_audio_enabled(self) -> bool:
"""Return if any audio stream enabled."""
return await self.async_is_audio_enabled()

def is_audio_enabled(
self, *, channel: int = 0, stream: str = "Main", stream_type: int = 0
) -> bool:
Expand All @@ -160,16 +185,24 @@ def is_audio_enabled(
)
return is_enabled[channel]

async def async_is_audio_enabled(
self, *, channel: int = 0, stream: str = "Main", stream_type: int = 0
) -> bool:
"""Return if any audio stream enabled on the given channel."""
is_enabled = utils.extract_audio_video_enabled(
f"{stream}Format[{stream_type}].Audio",
await self.async_encode_media, # type: ignore[attr-defined]
)
return is_enabled[channel]

def set_audio_enabled(self, enable: bool, *, channel: int = 0) -> None:
"""Enable/disable all audio streams on given channel."""
self.command(utils.enable_audio_video_cmd("Audio", enable, channel))

@property
def audio_enabled(self) -> bool:
"""Return if any audio stream enabled."""
return self.is_audio_enabled()

@audio_enabled.setter
def audio_enabled(self, enable: bool) -> None:
"""Enable/disable all audio streams."""
self.set_audio_enabled(enable)
async def async_set_audio_enabled(
self, enable: bool, *, channel: int = 0
) -> None:
"""Enable/disable all audio streams on given channel."""
await self.async_command(
utils.enable_audio_video_cmd("Audio", enable, channel)
)
Loading

0 comments on commit 180f1ea

Please sign in to comment.