From 2ed3693236027de6103b4c6db7ba77868cf476b3 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 6 Jul 2023 11:39:32 +0200 Subject: [PATCH] Mark scripts as response optional, make it always return a response if return_response is set --- homeassistant/components/script/__init__.py | 2 +- homeassistant/helpers/service.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/script/__init__.py b/homeassistant/components/script/__init__.py index f8d41db0e11..8530aa3b04c 100644 --- a/homeassistant/components/script/__init__.py +++ b/homeassistant/components/script/__init__.py @@ -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: diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index 715a960de5d..a1dc22ea4a1 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -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