Skip to content

Commit

Permalink
Mark scripts as response optional, make it always return a response i…
Browse files Browse the repository at this point in the history
…f return_response is set
  • Loading branch information
bramkragten committed Jul 6, 2023
1 parent de24860 commit 2ed3693
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion homeassistant/components/script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ async def _service_handler(self, service: ServiceCall) -> ServiceResponse:
variables=service.data, context=service.context, wait=True
)
if service.return_response:
return response
return response or {}
return None

async def async_added_to_hass(self) -> None:
Expand Down
7 changes: 7 additions & 0 deletions homeassistant/helpers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2ed3693

Please sign in to comment.