Add service response values to service descriptions (#95262)
parent
fa03324bbd
commit
d95c241a1a
|
@ -31,6 +31,7 @@ from homeassistant.core import (
|
|||
HomeAssistant,
|
||||
ServiceCall,
|
||||
ServiceResponse,
|
||||
SupportsResponse,
|
||||
callback,
|
||||
)
|
||||
from homeassistant.exceptions import (
|
||||
|
@ -635,6 +636,13 @@ async def async_get_all_descriptions(
|
|||
if "target" in yaml_description:
|
||||
description["target"] = yaml_description["target"]
|
||||
|
||||
if (
|
||||
response := hass.services.supports_response(domain, service)
|
||||
) != SupportsResponse.NONE:
|
||||
description["response"] = {
|
||||
"optional": response == SupportsResponse.OPTIONAL,
|
||||
}
|
||||
|
||||
descriptions_cache[cache_key] = description
|
||||
|
||||
descriptions[domain][service] = description
|
||||
|
|
|
@ -18,7 +18,7 @@ from homeassistant.const import (
|
|||
STATE_ON,
|
||||
EntityCategory,
|
||||
)
|
||||
from homeassistant.core import Context, HomeAssistant, ServiceCall
|
||||
from homeassistant.core import Context, HomeAssistant, ServiceCall, SupportsResponse
|
||||
from homeassistant.helpers import (
|
||||
device_registry as dr,
|
||||
entity_registry as er,
|
||||
|
@ -575,8 +575,31 @@ async def test_async_get_all_descriptions(hass: HomeAssistant) -> None:
|
|||
hass.services.async_register(
|
||||
logger.DOMAIN, "another_new_service", lambda x: None, None
|
||||
)
|
||||
hass.services.async_register(
|
||||
logger.DOMAIN,
|
||||
"service_with_optional_response",
|
||||
lambda x: None,
|
||||
None,
|
||||
SupportsResponse.OPTIONAL,
|
||||
)
|
||||
hass.services.async_register(
|
||||
logger.DOMAIN,
|
||||
"service_with_only_response",
|
||||
lambda x: None,
|
||||
None,
|
||||
SupportsResponse.ONLY,
|
||||
)
|
||||
|
||||
descriptions = await service.async_get_all_descriptions(hass)
|
||||
assert "another_new_service" in descriptions[logger.DOMAIN]
|
||||
assert "service_with_optional_response" in descriptions[logger.DOMAIN]
|
||||
assert descriptions[logger.DOMAIN]["service_with_optional_response"][
|
||||
"response"
|
||||
] == {"optional": True}
|
||||
assert "service_with_only_response" in descriptions[logger.DOMAIN]
|
||||
assert descriptions[logger.DOMAIN]["service_with_only_response"]["response"] == {
|
||||
"optional": False
|
||||
}
|
||||
|
||||
# Verify the cache returns the same object
|
||||
assert await service.async_get_all_descriptions(hass) is descriptions
|
||||
|
|
Loading…
Reference in New Issue