Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 7 additions & 4 deletions tests/components/script/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
callback,
split_entity_id,
)
from homeassistant.exceptions import HomeAssistantError, ServiceNotFound
from homeassistant.exceptions import ServiceNotFound
from homeassistant.helpers import entity_registry as er, template
from homeassistant.helpers.event import async_track_state_change
from homeassistant.helpers.script import (
Expand Down Expand Up @@ -1625,7 +1625,7 @@ async def test_responses(hass: HomeAssistant, response: Any) -> None:
)


async def test_responses_error(hass: HomeAssistant) -> None:
async def test_responses_no_response(hass: HomeAssistant) -> None:
"""Test response variable not set."""
mock_restore_cache(hass, ())
assert await async_setup_component(
Expand All @@ -1645,10 +1645,13 @@ async def test_responses_error(hass: HomeAssistant) -> None:
},
)

with pytest.raises(HomeAssistantError):
assert await hass.services.async_call(
# Validate we can call it with return_response
assert (
await hass.services.async_call(
DOMAIN, "test", {"greeting": "world"}, blocking=True, return_response=True
)
== {}
)
# Validate we can also call it without return_response
assert (
await hass.services.async_call(
Expand Down