Fix missing response for queued mode scripts (#141460)

This commit is contained in:
alorente 2025-03-28 11:47:41 +01:00 committed by GitHub
parent 93f12fb7c6
commit 63df2474a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 5 deletions

View File

@ -1311,7 +1311,7 @@ class _QueuedScriptRun(_ScriptRun):
lock_acquired = False
async def async_run(self) -> None:
async def async_run(self) -> ScriptRunResult | None:
"""Run script."""
# Wait for previous run, if any, to finish by attempting to acquire the script's
# shared lock. At the same time monitor if we've been told to stop.
@ -1325,7 +1325,7 @@ class _QueuedScriptRun(_ScriptRun):
self.lock_acquired = True
# We've acquired the lock so we can go ahead and start the run.
await super().async_run()
return await super().async_run()
def _finish(self) -> None:
if self.lock_acquired:

View File

@ -5853,14 +5853,16 @@ async def test_stop_action_subscript(
)
@pytest.mark.parametrize(("var", "response"), [(1, "If: Then"), (2, "Testing 123")])
@pytest.mark.parametrize(
("var", "response"),
[(1, "If: Then"), (2, "Testing 123")],
("script_mode", "max_runs"), [("single", 1), ("parallel", 2), ("queued", 2)]
)
async def test_stop_action_response_variables(
hass: HomeAssistant,
var: int,
response: str,
script_mode,
max_runs,
) -> None:
"""Test setting stop response_variable in a subscript."""
sequence = cv.SCRIPT_SCHEMA(
@ -5879,7 +5881,14 @@ async def test_stop_action_response_variables(
{"stop": "In the name of love", "response_variable": "output"},
]
)
script_obj = script.Script(hass, sequence, "Test Name", "test_domain")
script_obj = script.Script(
hass,
sequence,
"Test Name",
"test_domain",
script_mode=script_mode,
max_runs=max_runs,
)
run_vars = MappingProxyType({"var": var})
result = await script_obj.async_run(run_vars, context=Context())