mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 10:59:40 +00:00
Add sequence action for automations & scripts (#117690)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
@@ -3538,6 +3538,103 @@ async def test_if_condition_validation(
|
||||
)
|
||||
|
||||
|
||||
async def test_sequence(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test sequence action."""
|
||||
events = async_capture_events(hass, "test_event")
|
||||
|
||||
sequence = cv.SCRIPT_SCHEMA(
|
||||
[
|
||||
{
|
||||
"alias": "Sequential group",
|
||||
"sequence": [
|
||||
{
|
||||
"alias": "sequence group, action 1",
|
||||
"event": "test_event",
|
||||
"event_data": {
|
||||
"sequence": "group",
|
||||
"action": "1",
|
||||
"what": "{{ what }}",
|
||||
},
|
||||
},
|
||||
{
|
||||
"alias": "sequence group, action 2",
|
||||
"event": "test_event",
|
||||
"event_data": {
|
||||
"sequence": "group",
|
||||
"action": "2",
|
||||
"what": "{{ what }}",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"alias": "action 2",
|
||||
"event": "test_event",
|
||||
"event_data": {"action": "2", "what": "{{ what }}"},
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
script_obj = script.Script(hass, sequence, "Test Name", "test_domain")
|
||||
|
||||
await script_obj.async_run(MappingProxyType({"what": "world"}), Context())
|
||||
|
||||
assert len(events) == 3
|
||||
assert events[0].data == {
|
||||
"sequence": "group",
|
||||
"action": "1",
|
||||
"what": "world",
|
||||
}
|
||||
assert events[1].data == {
|
||||
"sequence": "group",
|
||||
"action": "2",
|
||||
"what": "world",
|
||||
}
|
||||
assert events[2].data == {
|
||||
"action": "2",
|
||||
"what": "world",
|
||||
}
|
||||
|
||||
assert (
|
||||
"Test Name: Sequential group: Executing step sequence group, action 1"
|
||||
in caplog.text
|
||||
)
|
||||
assert (
|
||||
"Test Name: Sequential group: Executing step sequence group, action 2"
|
||||
in caplog.text
|
||||
)
|
||||
assert "Test Name: Executing step action 2" in caplog.text
|
||||
|
||||
expected_trace = {
|
||||
"0": [{"variables": {"what": "world"}}],
|
||||
"0/sequence/0": [
|
||||
{
|
||||
"result": {
|
||||
"event": "test_event",
|
||||
"event_data": {"sequence": "group", "action": "1", "what": "world"},
|
||||
},
|
||||
}
|
||||
],
|
||||
"0/sequence/1": [
|
||||
{
|
||||
"result": {
|
||||
"event": "test_event",
|
||||
"event_data": {"sequence": "group", "action": "2", "what": "world"},
|
||||
},
|
||||
}
|
||||
],
|
||||
"1": [
|
||||
{
|
||||
"result": {
|
||||
"event": "test_event",
|
||||
"event_data": {"action": "2", "what": "world"},
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
assert_action_trace(expected_trace)
|
||||
|
||||
|
||||
async def test_parallel(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test parallel action."""
|
||||
events = async_capture_events(hass, "test_event")
|
||||
@@ -5167,6 +5264,9 @@ async def test_validate_action_config(
|
||||
cv.SCRIPT_ACTION_PARALLEL: {
|
||||
"parallel": [templated_device_action("parallel_event")],
|
||||
},
|
||||
cv.SCRIPT_ACTION_SEQUENCE: {
|
||||
"sequence": [templated_device_action("sequence_event")],
|
||||
},
|
||||
cv.SCRIPT_ACTION_SET_CONVERSATION_RESPONSE: {
|
||||
"set_conversation_response": "Hello world"
|
||||
},
|
||||
@@ -5179,6 +5279,7 @@ async def test_validate_action_config(
|
||||
cv.SCRIPT_ACTION_WAIT_FOR_TRIGGER: None,
|
||||
cv.SCRIPT_ACTION_IF: None,
|
||||
cv.SCRIPT_ACTION_PARALLEL: None,
|
||||
cv.SCRIPT_ACTION_SEQUENCE: None,
|
||||
}
|
||||
|
||||
for key in cv.ACTION_TYPE_SCHEMAS:
|
||||
|
||||
Reference in New Issue
Block a user