Skip to content

Commit fbefe2e

Browse files
mj23000adamlogan73
andauthored
Add async Websocket client (#212)
* Add base Websocket class * Add Async Websocket client * Rework structure and fix typing * Fix typing * Add testing * Use breaks instead of zip(range(1), ...) in async event tests * fixes from rebase * Add config entry websocket methods and fix Domain.from_json usage Use Domain.from_json_with_client() in websocket clients since Domain requires a client reference. Add config entry methods (get, disable, enable, ignore flow, subentries, subscribe) to RawWebsocketClient. * Add async config entry methods and improve test coverage to 99% Add async counterparts for all config entry websocket methods in RawAsyncWebsocketClient. Add async tests for websocket state, entity, config entry, and error path coverage. Fix conftest return type annotation, replace zip(range) with break, and use pytest.raises instead of try/except in error tests. --------- Co-authored-by: Adam Logan <adamlogan73@gmail.com>
1 parent 4ef4c92 commit fbefe2e

11 files changed

Lines changed: 1650 additions & 595 deletions

homeassistant_api/models/domains.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ class ServiceFieldSelectorObject(BaseModel):
383383
class ServiceFieldSelectorQRCode(BaseModel):
384384
data: str
385385
scale: Optional[Union[int, float]] = None
386-
error_correction_level: Optional[
387-
ServiceFieldSelectorQRCodeErrorCorrectionLevel
388-
] = None
386+
error_correction_level: Optional[ServiceFieldSelectorQRCodeErrorCorrectionLevel] = (
387+
None
388+
)
389389
center_image: Optional[str] = None
390390

391391

@@ -614,14 +614,13 @@ def trigger(
614614

615615
async def async_trigger(
616616
self, **service_data
617-
) -> Union[Tuple[State, ...], Tuple[Tuple[State, ...], dict[str, JSONType]]]:
617+
) -> Union[
618+
Tuple[State, ...],
619+
None,
620+
dict[str, JSONType],
621+
tuple[tuple[State, ...], dict[str, JSONType]],
622+
]:
618623
"""Triggers the service associated with this object."""
619-
from homeassistant_api import WebsocketClient # prevent circular import
620-
621-
if isinstance(self.domain._client, WebsocketClient):
622-
raise NotImplementedError(
623-
"WebsocketClient does not support async/await syntax."
624-
)
625624
try:
626625
return await self.domain._client.async_trigger_service_with_response(
627626
self.domain.domain_id,
@@ -647,7 +646,12 @@ def __call__(
647646
Coroutine[
648647
Any,
649648
Any,
650-
Union[Tuple[State, ...], Tuple[Tuple[State, ...], dict[str, JSONType]]],
649+
Union[
650+
Tuple[State, ...],
651+
Tuple[Tuple[State, ...], dict[str, JSONType]],
652+
dict[str, JSONType],
653+
None,
654+
],
651655
],
652656
]:
653657
"""

0 commit comments

Comments
 (0)