mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Set correct response
value in service description when async_set_service_schema
is used (#95985)
* Mark scripts as response optional, make it always return a response if return_response is set * Update test_init.py * Revert "Update test_init.py" This reverts commit 8e113e54dbf183db06e1d1f0fea95d6bc59e4e80. * Split + add test
This commit is contained in:
parent
8015d4c7b4
commit
342d07cb92
@ -678,6 +678,13 @@ def async_set_service_schema(
|
||||
if "target" in schema:
|
||||
description["target"] = schema["target"]
|
||||
|
||||
if (
|
||||
response := hass.services.supports_response(domain, service)
|
||||
) != SupportsResponse.NONE:
|
||||
description["response"] = {
|
||||
"optional": response == SupportsResponse.OPTIONAL,
|
||||
}
|
||||
|
||||
hass.data.pop(ALL_SERVICE_DESCRIPTIONS_CACHE, None)
|
||||
hass.data[SERVICE_DESCRIPTION_CACHE][(domain, service)] = description
|
||||
|
||||
|
@ -589,6 +589,19 @@ async def test_async_get_all_descriptions(hass: HomeAssistant) -> None:
|
||||
None,
|
||||
SupportsResponse.ONLY,
|
||||
)
|
||||
hass.services.async_register(
|
||||
logger.DOMAIN,
|
||||
"another_service_with_response",
|
||||
lambda x: None,
|
||||
None,
|
||||
SupportsResponse.OPTIONAL,
|
||||
)
|
||||
service.async_set_service_schema(
|
||||
hass,
|
||||
logger.DOMAIN,
|
||||
"another_service_with_response",
|
||||
{"description": "response service"},
|
||||
)
|
||||
|
||||
descriptions = await service.async_get_all_descriptions(hass)
|
||||
assert "another_new_service" in descriptions[logger.DOMAIN]
|
||||
@ -600,6 +613,10 @@ async def test_async_get_all_descriptions(hass: HomeAssistant) -> None:
|
||||
assert descriptions[logger.DOMAIN]["service_with_only_response"]["response"] == {
|
||||
"optional": False
|
||||
}
|
||||
assert "another_service_with_response" in descriptions[logger.DOMAIN]
|
||||
assert descriptions[logger.DOMAIN]["another_service_with_response"]["response"] == {
|
||||
"optional": True
|
||||
}
|
||||
|
||||
# Verify the cache returns the same object
|
||||
assert await service.async_get_all_descriptions(hass) is descriptions
|
||||
|
Loading…
x
Reference in New Issue
Block a user