Add service response support to admin services (#144837)
This commit is contained in:
@@ -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 = []
|
||||
|
||||
Reference in New Issue
Block a user