diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index 3eacc8d6629..fa0e57d501c 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -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 diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index 845b5bacd1a..f6299312b53 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -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