Add service response support to admin services (#144837)

This commit is contained in:
Abílio Costa
2025-05-13 21:57:15 +01:00
committed by GitHub
parent de2cbb7f5c
commit 6d809b0b5a
2 changed files with 50 additions and 7 deletions

View File

@@ -32,6 +32,7 @@ from homeassistant.core import (
HassJob,
HomeAssistant,
ServiceCall,
ServiceResponse,
SupportsResponse,
)
from homeassistant.helpers import (
@@ -1648,6 +1649,33 @@ async def test_register_admin_service(
assert calls[0].context.user_id == hass_admin_user.id
@pytest.mark.parametrize(
"supports_response",
[SupportsResponse.ONLY, SupportsResponse.OPTIONAL],
)
async def test_register_admin_service_return_response(
hass: HomeAssistant, supports_response: SupportsResponse
) -> None:
"""Test the register admin service for a service that returns response data."""
async def mock_service(call: ServiceCall) -> ServiceResponse:
"""Service handler coroutine."""
assert call.return_response
return {"test-reply": "test-value1"}
service.async_register_admin_service(
hass, "test", "test", mock_service, supports_response=supports_response
)
result = await hass.services.async_call(
"test",
"test",
service_data={},
blocking=True,
return_response=True,
)
assert result == {"test-reply": "test-value1"}
async def test_domain_control_not_async(hass: HomeAssistant, mock_entities) -> None:
"""Test domain verification in a service call with an unknown user."""
calls = []