Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions homeassistant_api/models/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def __init__(

@classmethod
def from_json(
cls, json: Dict[str, JSONType], client: Union["Client", "WebsocketClient"]
cls,
json: Dict[str, JSONType],
client: Union["Client", "WebsocketClient"],
) -> "Domain":
"""Constructs Domain and Service models from json data."""
if "domain" not in json or "services" not in json:
Expand Down Expand Up @@ -583,7 +585,9 @@ class Service(BaseModel):
target: Optional[ServiceFieldSelectorTarget] = None
response: Optional[ServiceResponse] = None

def trigger(self, **service_data) -> Union[
def trigger(
self, **service_data
) -> Union[
Tuple[State, ...],
Tuple[Tuple[State, ...], dict[str, JSONType]],
dict[str, JSONType],
Expand All @@ -605,14 +609,13 @@ def trigger(self, **service_data) -> Union[

async def async_trigger(
self, **service_data
) -> Union[Tuple[State, ...], Tuple[Tuple[State, ...], dict[str, JSONType]]]:
) -> Union[
Tuple[State, ...],
None,
dict[str, JSONType],
tuple[tuple[State, ...], dict[str, JSONType]],
]:
"""Triggers the service associated with this object."""
from homeassistant_api import WebsocketClient # prevent circular import

if isinstance(self.domain._client, WebsocketClient):
raise NotImplementedError(
"WebsocketClient does not support async/await syntax."
)
try:
return await self.domain._client.async_trigger_service_with_response(
self.domain.domain_id,
Expand All @@ -626,7 +629,9 @@ async def async_trigger(
**service_data,
)

def __call__(self, **service_data) -> Union[
def __call__(
self, **service_data
) -> Union[
Union[
Tuple[State, ...],
Tuple[Tuple[State, ...], dict[str, JSONType]],
Expand All @@ -636,7 +641,12 @@ def __call__(self, **service_data) -> Union[
Coroutine[
Any,
Any,
Union[Tuple[State, ...], Tuple[Tuple[State, ...], dict[str, JSONType]]],
Union[
Tuple[State, ...],
Tuple[Tuple[State, ...], dict[str, JSONType]],
dict[str, JSONType],
None,
],
],
]:
"""
Expand Down
Loading