Rename 'service' to 'action' in automations and scripts (#122845)
This commit is contained in:
parent
f14471112d
commit
8b96c7873f
11 changed files with 414 additions and 275 deletions
|
@ -85,7 +85,7 @@ async def test_passing_variables(hass: HomeAssistant) -> None:
|
|||
"script": {
|
||||
"test": {
|
||||
"sequence": {
|
||||
"service": "test.script",
|
||||
"action": "test.script",
|
||||
"data_template": {"hello": "{{ greeting }}"},
|
||||
}
|
||||
}
|
||||
|
@ -115,8 +115,14 @@ async def test_passing_variables(hass: HomeAssistant) -> None:
|
|||
|
||||
|
||||
@pytest.mark.parametrize("toggle", [False, True])
|
||||
async def test_turn_on_off_toggle(hass: HomeAssistant, toggle) -> None:
|
||||
"""Verify turn_on, turn_off & toggle services."""
|
||||
@pytest.mark.parametrize("action_schema_variations", ["action", "service"])
|
||||
async def test_turn_on_off_toggle(
|
||||
hass: HomeAssistant, toggle: bool, action_schema_variations: str
|
||||
) -> None:
|
||||
"""Verify turn_on, turn_off & toggle services.
|
||||
|
||||
Ensures backward compatibility with the old service action schema is maintained.
|
||||
"""
|
||||
event = "test_event"
|
||||
event_mock = Mock()
|
||||
|
||||
|
@ -132,9 +138,15 @@ async def test_turn_on_off_toggle(hass: HomeAssistant, toggle) -> None:
|
|||
async_track_state_change(hass, ENTITY_ID, state_listener, to_state="on")
|
||||
|
||||
if toggle:
|
||||
turn_off_step = {"service": "script.toggle", "entity_id": ENTITY_ID}
|
||||
turn_off_step = {
|
||||
action_schema_variations: "script.toggle",
|
||||
"entity_id": ENTITY_ID,
|
||||
}
|
||||
else:
|
||||
turn_off_step = {"service": "script.turn_off", "entity_id": ENTITY_ID}
|
||||
turn_off_step = {
|
||||
action_schema_variations: "script.turn_off",
|
||||
"entity_id": ENTITY_ID,
|
||||
}
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"script",
|
||||
|
@ -165,7 +177,7 @@ async def test_turn_on_off_toggle(hass: HomeAssistant, toggle) -> None:
|
|||
invalid_configs = [
|
||||
{"test": {}},
|
||||
{"test hello world": {"sequence": [{"event": "bla"}]}},
|
||||
{"test": {"sequence": {"event": "test_event", "service": "homeassistant.turn_on"}}},
|
||||
{"test": {"sequence": {"event": "test_event", "action": "homeassistant.turn_on"}}},
|
||||
]
|
||||
|
||||
|
||||
|
@ -180,7 +192,7 @@ invalid_configs = [
|
|||
"test": {
|
||||
"sequence": {
|
||||
"event": "test_event",
|
||||
"service": "homeassistant.turn_on",
|
||||
"action": "homeassistant.turn_on",
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -235,7 +247,7 @@ async def test_bad_config_validation_critical(
|
|||
"good_script": {
|
||||
"alias": "good_script",
|
||||
"sequence": {
|
||||
"service": "test.automation",
|
||||
"action": "test.automation",
|
||||
"entity_id": "hello.world",
|
||||
},
|
||||
},
|
||||
|
@ -300,7 +312,7 @@ async def test_bad_config_validation(
|
|||
"good_script": {
|
||||
"alias": "good_script",
|
||||
"sequence": {
|
||||
"service": "test.automation",
|
||||
"action": "test.automation",
|
||||
"entity_id": "hello.world",
|
||||
},
|
||||
},
|
||||
|
@ -342,7 +354,7 @@ async def test_bad_config_validation(
|
|||
object_id: {
|
||||
"alias": "bad_script",
|
||||
"sequence": {
|
||||
"service": "test.automation",
|
||||
"action": "test.automation",
|
||||
"entity_id": "hello.world",
|
||||
},
|
||||
},
|
||||
|
@ -430,7 +442,7 @@ async def test_reload_unchanged_does_not_stop(
|
|||
"sequence": [
|
||||
{"event": "running"},
|
||||
{"wait_template": "{{ is_state('test.entity', 'goodbye') }}"},
|
||||
{"service": "test.script"},
|
||||
{"action": "test.script"},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
@ -473,13 +485,13 @@ async def test_reload_unchanged_does_not_stop(
|
|||
[
|
||||
{
|
||||
"test": {
|
||||
"sequence": [{"service": "test.script"}],
|
||||
"sequence": [{"action": "test.script"}],
|
||||
}
|
||||
},
|
||||
# A script using templates
|
||||
{
|
||||
"test": {
|
||||
"sequence": [{"service": "{{ 'test.script' }}"}],
|
||||
"sequence": [{"action": "{{ 'test.script' }}"}],
|
||||
}
|
||||
},
|
||||
# A script using blueprint
|
||||
|
@ -666,7 +678,7 @@ async def test_logging_script_error(
|
|||
assert await async_setup_component(
|
||||
hass,
|
||||
"script",
|
||||
{"script": {"hello": {"sequence": [{"service": "non.existing"}]}}},
|
||||
{"script": {"hello": {"sequence": [{"action": "non.existing"}]}}},
|
||||
)
|
||||
with pytest.raises(ServiceNotFound) as err:
|
||||
await hass.services.async_call("script", "hello", blocking=True)
|
||||
|
@ -690,7 +702,7 @@ async def test_async_get_descriptions_script(hass: HomeAssistant) -> None:
|
|||
"""Test async_set_service_schema for the script integration."""
|
||||
script_config = {
|
||||
DOMAIN: {
|
||||
"test1": {"sequence": [{"service": "homeassistant.restart"}]},
|
||||
"test1": {"sequence": [{"action": "homeassistant.restart"}]},
|
||||
"test2": {
|
||||
"description": "test2",
|
||||
"fields": {
|
||||
|
@ -699,7 +711,7 @@ async def test_async_get_descriptions_script(hass: HomeAssistant) -> None:
|
|||
"example": "param_example",
|
||||
}
|
||||
},
|
||||
"sequence": [{"service": "homeassistant.restart"}],
|
||||
"sequence": [{"action": "homeassistant.restart"}],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -795,11 +807,11 @@ async def test_extraction_functions(
|
|||
"test1": {
|
||||
"sequence": [
|
||||
{
|
||||
"service": "test.script",
|
||||
"action": "test.script",
|
||||
"data": {"entity_id": "light.in_both"},
|
||||
},
|
||||
{
|
||||
"service": "test.script",
|
||||
"action": "test.script",
|
||||
"data": {"entity_id": "light.in_first"},
|
||||
},
|
||||
{
|
||||
|
@ -809,15 +821,15 @@ async def test_extraction_functions(
|
|||
"device_id": device_in_both.id,
|
||||
},
|
||||
{
|
||||
"service": "test.test",
|
||||
"action": "test.test",
|
||||
"target": {"area_id": "area-in-both"},
|
||||
},
|
||||
{
|
||||
"service": "test.test",
|
||||
"action": "test.test",
|
||||
"target": {"floor_id": "floor-in-both"},
|
||||
},
|
||||
{
|
||||
"service": "test.test",
|
||||
"action": "test.test",
|
||||
"target": {"label_id": "label-in-both"},
|
||||
},
|
||||
]
|
||||
|
@ -825,7 +837,7 @@ async def test_extraction_functions(
|
|||
"test2": {
|
||||
"sequence": [
|
||||
{
|
||||
"service": "test.script",
|
||||
"action": "test.script",
|
||||
"data": {"entity_id": "light.in_both"},
|
||||
},
|
||||
{
|
||||
|
@ -851,7 +863,7 @@ async def test_extraction_functions(
|
|||
"test3": {
|
||||
"sequence": [
|
||||
{
|
||||
"service": "test.script",
|
||||
"action": "test.script",
|
||||
"data": {"entity_id": "light.in_both"},
|
||||
},
|
||||
{
|
||||
|
@ -861,27 +873,27 @@ async def test_extraction_functions(
|
|||
},
|
||||
{"scene": "scene.hello"},
|
||||
{
|
||||
"service": "test.test",
|
||||
"action": "test.test",
|
||||
"target": {"area_id": "area-in-both"},
|
||||
},
|
||||
{
|
||||
"service": "test.test",
|
||||
"action": "test.test",
|
||||
"target": {"area_id": "area-in-last"},
|
||||
},
|
||||
{
|
||||
"service": "test.test",
|
||||
"action": "test.test",
|
||||
"target": {"floor_id": "floor-in-both"},
|
||||
},
|
||||
{
|
||||
"service": "test.test",
|
||||
"action": "test.test",
|
||||
"target": {"floor_id": "floor-in-last"},
|
||||
},
|
||||
{
|
||||
"service": "test.test",
|
||||
"action": "test.test",
|
||||
"target": {"label_id": "label-in-both"},
|
||||
},
|
||||
{
|
||||
"service": "test.test",
|
||||
"action": "test.test",
|
||||
"target": {"label_id": "label-in-last"},
|
||||
},
|
||||
],
|
||||
|
@ -1028,11 +1040,11 @@ async def test_concurrent_script(hass: HomeAssistant, concurrently) -> None:
|
|||
"""Test calling script concurrently or not."""
|
||||
if concurrently:
|
||||
call_script_2 = {
|
||||
"service": "script.turn_on",
|
||||
"action": "script.turn_on",
|
||||
"data": {"entity_id": "script.script2"},
|
||||
}
|
||||
else:
|
||||
call_script_2 = {"service": "script.script2"}
|
||||
call_script_2 = {"action": "script.script2"}
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"script",
|
||||
|
@ -1045,17 +1057,17 @@ async def test_concurrent_script(hass: HomeAssistant, concurrently) -> None:
|
|||
{
|
||||
"wait_template": "{{ is_state('input_boolean.test1', 'on') }}"
|
||||
},
|
||||
{"service": "test.script", "data": {"value": "script1"}},
|
||||
{"action": "test.script", "data": {"value": "script1"}},
|
||||
],
|
||||
},
|
||||
"script2": {
|
||||
"mode": "parallel",
|
||||
"sequence": [
|
||||
{"service": "test.script", "data": {"value": "script2a"}},
|
||||
{"action": "test.script", "data": {"value": "script2a"}},
|
||||
{
|
||||
"wait_template": "{{ is_state('input_boolean.test2', 'on') }}"
|
||||
},
|
||||
{"service": "test.script", "data": {"value": "script2b"}},
|
||||
{"action": "test.script", "data": {"value": "script2b"}},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
@ -1126,7 +1138,7 @@ async def test_script_variables(
|
|||
},
|
||||
"sequence": [
|
||||
{
|
||||
"service": "test.script",
|
||||
"action": "test.script",
|
||||
"data": {
|
||||
"value": "{{ test_var }}",
|
||||
"templated_config_var": "{{ templated_config_var }}",
|
||||
|
@ -1142,7 +1154,7 @@ async def test_script_variables(
|
|||
},
|
||||
"sequence": [
|
||||
{
|
||||
"service": "test.script",
|
||||
"action": "test.script",
|
||||
"data": {
|
||||
"value": "{{ test_var }}",
|
||||
},
|
||||
|
@ -1155,7 +1167,7 @@ async def test_script_variables(
|
|||
},
|
||||
"sequence": [
|
||||
{
|
||||
"service": "test.script",
|
||||
"action": "test.script",
|
||||
"data": {
|
||||
"value": "{{ test_var }}",
|
||||
},
|
||||
|
@ -1221,7 +1233,7 @@ async def test_script_this_var_always(
|
|||
"script1": {
|
||||
"sequence": [
|
||||
{
|
||||
"service": "test.script",
|
||||
"action": "test.script",
|
||||
"data": {
|
||||
"this_template": "{{this.entity_id}}",
|
||||
},
|
||||
|
@ -1306,8 +1318,8 @@ async def test_recursive_script(
|
|||
"script1": {
|
||||
"mode": script_mode,
|
||||
"sequence": [
|
||||
{"service": "script.script1"},
|
||||
{"service": "test.script"},
|
||||
{"action": "script.script1"},
|
||||
{"action": "test.script"},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
@ -1356,26 +1368,26 @@ async def test_recursive_script_indirect(
|
|||
"script1": {
|
||||
"mode": script_mode,
|
||||
"sequence": [
|
||||
{"service": "script.script2"},
|
||||
{"action": "script.script2"},
|
||||
],
|
||||
},
|
||||
"script2": {
|
||||
"mode": script_mode,
|
||||
"sequence": [
|
||||
{"service": "script.script3"},
|
||||
{"action": "script.script3"},
|
||||
],
|
||||
},
|
||||
"script3": {
|
||||
"mode": script_mode,
|
||||
"sequence": [
|
||||
{"service": "script.script4"},
|
||||
{"action": "script.script4"},
|
||||
],
|
||||
},
|
||||
"script4": {
|
||||
"mode": script_mode,
|
||||
"sequence": [
|
||||
{"service": "script.script1"},
|
||||
{"service": "test.script"},
|
||||
{"action": "script.script1"},
|
||||
{"action": "test.script"},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
@ -1440,10 +1452,10 @@ async def test_recursive_script_turn_on(
|
|||
"condition": "template",
|
||||
"value_template": "{{ request == 'step_2' }}",
|
||||
},
|
||||
"sequence": {"service": "test.script_done"},
|
||||
"sequence": {"action": "test.script_done"},
|
||||
},
|
||||
"default": {
|
||||
"service": "script.turn_on",
|
||||
"action": "script.turn_on",
|
||||
"data": {
|
||||
"entity_id": "script.script1",
|
||||
"variables": {"request": "step_2"},
|
||||
|
@ -1451,7 +1463,7 @@ async def test_recursive_script_turn_on(
|
|||
},
|
||||
},
|
||||
{
|
||||
"service": "script.turn_on",
|
||||
"action": "script.turn_on",
|
||||
"data": {"entity_id": "script.script1"},
|
||||
},
|
||||
],
|
||||
|
@ -1513,7 +1525,7 @@ async def test_websocket_config(
|
|||
"""Test config command."""
|
||||
config = {
|
||||
"alias": "hello",
|
||||
"sequence": [{"service": "light.turn_on"}],
|
||||
"sequence": [{"action": "light.turn_on"}],
|
||||
}
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
|
@ -1577,7 +1589,7 @@ async def test_script_service_changed_entity_id(
|
|||
"script": {
|
||||
"test": {
|
||||
"sequence": {
|
||||
"service": "test.script",
|
||||
"action": "test.script",
|
||||
"data_template": {"entity_id": "{{ this.entity_id }}"},
|
||||
}
|
||||
}
|
||||
|
@ -1658,7 +1670,7 @@ async def test_blueprint_script(hass: HomeAssistant, calls: list[ServiceCall]) -
|
|||
"a_number": 5,
|
||||
},
|
||||
"Blueprint 'Call service' generated invalid script",
|
||||
"value should be a string for dictionary value @ data['sequence'][0]['service']",
|
||||
"value should be a string for dictionary value @ data['sequence'][0]['action']",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
@ -1839,10 +1851,10 @@ async def test_script_queued_mode(hass: HomeAssistant) -> None:
|
|||
"sequence": [
|
||||
{
|
||||
"parallel": [
|
||||
{"service": "script.test_sub"},
|
||||
{"service": "script.test_sub"},
|
||||
{"service": "script.test_sub"},
|
||||
{"service": "script.test_sub"},
|
||||
{"action": "script.test_sub"},
|
||||
{"action": "script.test_sub"},
|
||||
{"action": "script.test_sub"},
|
||||
{"action": "script.test_sub"},
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -1850,7 +1862,7 @@ async def test_script_queued_mode(hass: HomeAssistant) -> None:
|
|||
"test_sub": {
|
||||
"mode": "queued",
|
||||
"sequence": [
|
||||
{"service": "test.simulated_remote"},
|
||||
{"action": "test.simulated_remote"},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue