Skip to content
Merged
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
24 changes: 24 additions & 0 deletions homeassistant_api/models/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,18 @@ def trigger(
**service_data,
)

def __call__(
self,
**service_data: Any,
) -> (
tuple[State, ...]
| tuple[tuple[State, ...], dict[str, Any]]
| dict[str, Any]
| None
):
"""Calls the service associated with this object."""
return self.trigger(**service_data)


class AsyncService(BaseService):
"""Async service with async trigger method."""
Expand Down Expand Up @@ -658,3 +670,15 @@ async def trigger(
self.service_id,
**service_data,
)

async def __call__(
self,
**service_data: Any,
) -> (
tuple[State, ...]
| tuple[tuple[State, ...], dict[str, Any]]
| dict[str, Any]
| None
):
"""Calls the service associated with this object."""
return await self.trigger(**service_data)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requires = ["hatchling"]

[project]
name = "HomeAssistant-API"
version = "6.0.0"
version = "6.0.1"
description = "Python Wrapper for Homeassistant's REST API"
readme = "README.md"
license = "GPL-3.0-or-later"
Expand Down
190 changes: 190 additions & 0 deletions tests/cassettes/test_endpoints/test_async_call_service.json

Large diffs are not rendered by default.

190 changes: 190 additions & 0 deletions tests/cassettes/test_endpoints/test_call_service.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,17 @@ def test_trigger_service(cached_client: Client) -> None:
logger.info(resp)
assert isinstance(resp, tuple)

def test_call_service(cached_client: Client) -> None:
"""Tests the `POST /api/services/<domain>/<service>` endpoint."""
notify = cached_client.get_domain("notify")
assert notify is not None
resp = notify.persistent_notification(
message="Your API Test Suite just said hello!",
title="Test Suite Notifcation",
)
logger.info(resp)
assert isinstance(resp, tuple)


async def test_async_trigger_service(async_cached_client: AsyncClient) -> None:
"""Tests the `POST /api/services/<domain>/<service>` endpoint."""
Expand All @@ -511,6 +522,17 @@ async def test_async_trigger_service(async_cached_client: AsyncClient) -> None:
assert isinstance(resp, tuple)


async def test_async_call_service(async_cached_client: AsyncClient) -> None:
"""Tests the `POST /api/services/<domain>/<service>` endpoint."""
notify = await async_cached_client.get_domain("notify")
assert notify is not None
resp = await notify.persistent_notification(
message="Your API Test Suite just said hello!",
title="Test Suite Notifcation (Async)",
)
assert isinstance(resp, tuple)


def test_websocket_trigger_service(websocket_client: WebsocketClient) -> None:
"""Tests the `"type": "trigger_service"` websocket command."""
notify = websocket_client.get_domain("notify")
Expand Down
Loading