Mark scripts as response optional, make it always return a response if return_response is set

pull/95985/head
Bram Kragten 2023-07-06 11:39:32 +02:00
parent de24860c87
commit 2ed3693236
No known key found for this signature in database
GPG Key ID: FBE2DFDB363EF55B
2 changed files with 8 additions and 1 deletions

View File

@ -608,7 +608,7 @@ class ScriptEntity(BaseScriptEntity, RestoreEntity):
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:

View File

@ -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