Skip to content

Add async APIs throughout#193

Merged
flacjacket merged 1 commit intotchellomello:masterfrom
flacjacket:async
Sep 16, 2021
Merged

Add async APIs throughout#193
flacjacket merged 1 commit intotchellomello:masterfrom
flacjacket:async

Conversation

@flacjacket
Copy link
Copy Markdown
Collaborator

Add a full suite of API functions that are able to use asyncio-based
calls. The async http requests are provided through httpx, which is
able to provide both basic auth and digest auth through its async
client. Using the async functions and the new async keywords requires
removing Python 3.6 support. In particular, this allows us to use async
and await keywoards. Setting up the async APIs unfortunately requires a
rough doubling of the API to add both sync and async code to get
functions of the appropriate color. Where there is a reasonable amount
of non-I/O logic, this is refactored out into common functions.

Add a full suite of API functions that are able to use asyncio-based
calls.  The async http requests are provided through httpx, which is
able to provide both basic auth and digest auth through its async
client.  Using the async functions and the new async keywords requires
removing Python 3.6 support.  In particular, this allows us to use async
and await keywoards.  Setting up the async APIs unfortunately requires a
rough doubling of the API to add both sync and async code to get
functions of the appropriate color.  Where there is a reasonable amount
of non-I/O logic, this is refactored out into common functions.
Comment thread src/amcrest/audio.py
"""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]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'attr'
undefined name 'defined'
undefined name 'ignore'

Comment thread src/amcrest/event.py
if key == "data":
value = {
data_key.replace('"', ""): data_value.replace('"', "")
for data_key, data_value in _REG_PARSE_MALFORMED_JSON.findall(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (82 > 79 characters)

Comment thread src/amcrest/log.py
)
return ret.content.decode()

async def async_log_show(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

Comment thread src/amcrest/ptz.py
return ret.content.decode()

async def async_ptz_presets_list(self, *, channel: int = 0) -> str:
ret = await self.async_command(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

Comment thread src/amcrest/record.py
return await self._async_get_config("Record")

async def async_set_record_config(self, rec_opt: str) -> str:
ret = await self.async_command(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

Comment thread src/amcrest/special.py
1-Extra Stream 1 (Sub Stream)
2-Extra Stream 2 (Sub Stream)
"""
return self._build_rtsp_url(self.rtsp_config, channel, typeno) # type: ignore[attr-defined]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (100 > 79 characters)
undefined name 'attr'
undefined name 'defined'
undefined name 'ignore'

Comment thread src/amcrest/storage.py

@property
async def async_storage_device_info(self) -> str:
ret = await self.async_command(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.


return self._user_manager(cmd)

async def async_modify_user(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

Comment thread src/amcrest/utils.py


def to_unit(value: Union[str, int, float], unit: str = "B") -> Tuple[str, str]:
def to_unit(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

Comment thread src/amcrest/video.py

@property
async def async_video_max_extra_streams(self) -> int:
ret = await self._async_magic_box(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

@flacjacket flacjacket merged commit 180f1ea into tchellomello:master Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants