Allow stopping a script with a response value (#95284)

This commit is contained in:
Paulus Schoutsen 2023-06-27 02:24:22 -04:00 committed by GitHub
parent 51aa2ba835
commit 5f14cdf69d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 140 additions and 28 deletions

View file

@ -1,6 +1,7 @@
"""The tests for the Script component."""
import asyncio
from datetime import timedelta
from typing import Any
from unittest.mock import Mock, patch
import pytest
@ -1502,3 +1503,34 @@ async def test_blueprint_script_fails_substitution(
"{'service_to_call': 'test.automation'}: No substitution found for input blah"
in caplog.text
)
@pytest.mark.parametrize("response", ({"value": 5}, '{"value": 5}'))
async def test_responses(hass: HomeAssistant, response: Any) -> None:
"""Test we can get responses."""
mock_restore_cache(hass, ())
assert await async_setup_component(
hass,
"script",
{
"script": {
"test": {
"sequence": {
"stop": "done",
"response": response,
}
}
}
},
)
assert await hass.services.async_call(
DOMAIN, "test", {"greeting": "world"}, blocking=True, return_response=True
) == {"value": 5}
# Validate we can also call it without return_response
assert (
await hass.services.async_call(
DOMAIN, "test", {"greeting": "world"}, blocking=True, return_response=False
)
is None
)