1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Rename 'service' to 'action' in automations and scripts (#122845)

This commit is contained in:
Franck Nijhof
2024-07-31 14:36:53 +02:00
committed by GitHub
parent f14471112d
commit 8b96c7873f
11 changed files with 414 additions and 275 deletions

View File

@@ -88,7 +88,7 @@ async def test_service_data_not_a_dict(
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation", "data": 100},
"action": {"action": "test.automation", "data": 100},
}
},
)
@@ -111,7 +111,7 @@ async def test_service_data_single_template(
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data": "{{ { 'foo': 'bar' } }}",
},
}
@@ -136,7 +136,7 @@ async def test_service_specify_data(
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data_template": {
"some": (
"{{ trigger.platform }} - {{ trigger.event.event_type }}"
@@ -170,7 +170,7 @@ async def test_service_specify_entity_id(
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation", "entity_id": "hello.world"},
"action": {"action": "test.automation", "entity_id": "hello.world"},
}
},
)
@@ -192,7 +192,7 @@ async def test_service_specify_entity_id_list(
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"entity_id": ["hello.world", "hello.world2"],
},
}
@@ -216,7 +216,7 @@ async def test_two_triggers(hass: HomeAssistant, calls: list[ServiceCall]) -> No
{"platform": "event", "event_type": "test_event"},
{"platform": "state", "entity_id": "test.entity"},
],
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
}
},
)
@@ -245,7 +245,7 @@ async def test_trigger_service_ignoring_condition(
"entity_id": "non.existing",
"above": "1",
},
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
}
},
)
@@ -301,7 +301,7 @@ async def test_two_conditions_with_and(
"below": 150,
},
],
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
}
},
)
@@ -333,7 +333,7 @@ async def test_shorthand_conditions_template(
automation.DOMAIN: {
"trigger": [{"platform": "event", "event_type": "test_event"}],
"condition": "{{ is_state('test.entity', 'hello') }}",
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
}
},
)
@@ -360,11 +360,11 @@ async def test_automation_list_setting(
automation.DOMAIN: [
{
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
},
{
"trigger": {"platform": "event", "event_type": "test_event_2"},
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
},
]
},
@@ -390,8 +390,8 @@ async def test_automation_calling_two_actions(
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"action": [
{"service": "test.automation", "data": {"position": 0}},
{"service": "test.automation", "data": {"position": 1}},
{"action": "test.automation", "data": {"position": 0}},
{"action": "test.automation", "data": {"position": 1}},
],
}
},
@@ -420,7 +420,7 @@ async def test_shared_context(hass: HomeAssistant, calls: list[ServiceCall]) ->
{
"alias": "bye",
"trigger": {"platform": "event", "event_type": "test_event2"},
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
},
]
},
@@ -486,7 +486,7 @@ async def test_services(hass: HomeAssistant, calls: list[ServiceCall]) -> None:
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
}
},
)
@@ -569,7 +569,7 @@ async def test_reload_config_service(
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data_template": {"event": "{{ trigger.event.event_type }}"},
},
}
@@ -597,7 +597,7 @@ async def test_reload_config_service(
"alias": "bye",
"trigger": {"platform": "event", "event_type": "test_event2"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data_template": {"event": "{{ trigger.event.event_type }}"},
},
}
@@ -650,7 +650,7 @@ async def test_reload_config_when_invalid_config(
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data_template": {"event": "{{ trigger.event.event_type }}"},
},
}
@@ -690,7 +690,7 @@ async def test_reload_config_handles_load_fails(
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data_template": {"event": "{{ trigger.event.event_type }}"},
},
}
@@ -735,7 +735,7 @@ async def test_automation_stops(
"action": [
{"event": "running"},
{"wait_template": "{{ is_state('test.entity', 'goodbye') }}"},
{"service": "test.automation"},
{"action": "test.automation"},
],
}
}
@@ -811,7 +811,7 @@ async def test_reload_unchanged_does_not_stop(
"action": [
{"event": "running"},
{"wait_template": "{{ is_state('test.entity', 'goodbye') }}"},
{"service": "test.automation"},
{"action": "test.automation"},
],
}
}
@@ -858,7 +858,7 @@ async def test_reload_single_unchanged_does_not_stop(
"action": [
{"event": "running"},
{"wait_template": "{{ is_state('test.entity', 'goodbye') }}"},
{"service": "test.automation"},
{"action": "test.automation"},
],
}
}
@@ -905,7 +905,7 @@ async def test_reload_single_add_automation(
"id": "sun",
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
}
}
assert await async_setup_component(hass, automation.DOMAIN, config1)
@@ -942,25 +942,25 @@ async def test_reload_single_parallel_calls(
"id": "sun",
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event_sun"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
},
{
"id": "moon",
"alias": "goodbye",
"trigger": {"platform": "event", "event_type": "test_event_moon"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
},
{
"id": "mars",
"alias": "goodbye",
"trigger": {"platform": "event", "event_type": "test_event_mars"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
},
{
"id": "venus",
"alias": "goodbye",
"trigger": {"platform": "event", "event_type": "test_event_venus"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
},
]
}
@@ -1055,7 +1055,7 @@ async def test_reload_single_remove_automation(
"id": "sun",
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
}
}
config2 = {automation.DOMAIN: {}}
@@ -1093,12 +1093,12 @@ async def test_reload_moved_automation_without_alias(
automation.DOMAIN: [
{
"trigger": {"platform": "event", "event_type": "test_event"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
},
{
"alias": "automation_with_alias",
"trigger": {"platform": "event", "event_type": "test_event2"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
},
]
}
@@ -1149,17 +1149,17 @@ async def test_reload_identical_automations_without_id(
{
"alias": "dolly",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
},
{
"alias": "dolly",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
},
{
"alias": "dolly",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
},
]
}
@@ -1246,12 +1246,12 @@ async def test_reload_identical_automations_without_id(
[
{
"trigger": {"platform": "event", "event_type": "test_event"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
},
# An automation using templates
{
"trigger": {"platform": "event", "event_type": "test_event"},
"action": [{"service": "{{ 'test.automation' }}"}],
"action": [{"action": "{{ 'test.automation' }}"}],
},
# An automation using blueprint
{
@@ -1278,13 +1278,13 @@ async def test_reload_identical_automations_without_id(
{
"id": "sun",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": [{"service": "test.automation"}],
"action": [{"action": "test.automation"}],
},
# An automation using templates
{
"id": "sun",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": [{"service": "{{ 'test.automation' }}"}],
"action": [{"action": "{{ 'test.automation' }}"}],
},
# An automation using blueprint
{
@@ -1424,12 +1424,12 @@ async def test_automation_restore_state(hass: HomeAssistant) -> None:
{
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event_hello"},
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
},
{
"alias": "bye",
"trigger": {"platform": "event", "event_type": "test_event_bye"},
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
},
]
}
@@ -1474,7 +1474,7 @@ async def test_initial_value_off(hass: HomeAssistant) -> None:
"alias": "hello",
"initial_state": "off",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation", "entity_id": "hello.world"},
"action": {"action": "test.automation", "entity_id": "hello.world"},
}
},
)
@@ -1499,7 +1499,7 @@ async def test_initial_value_on(hass: HomeAssistant) -> None:
"initial_state": "on",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"entity_id": ["hello.world", "hello.world2"],
},
}
@@ -1528,7 +1528,7 @@ async def test_initial_value_off_but_restore_on(hass: HomeAssistant) -> None:
"alias": "hello",
"initial_state": "off",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation", "entity_id": "hello.world"},
"action": {"action": "test.automation", "entity_id": "hello.world"},
}
},
)
@@ -1553,7 +1553,7 @@ async def test_initial_value_on_but_restore_off(hass: HomeAssistant) -> None:
"alias": "hello",
"initial_state": "on",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation", "entity_id": "hello.world"},
"action": {"action": "test.automation", "entity_id": "hello.world"},
}
},
)
@@ -1576,7 +1576,7 @@ async def test_no_initial_value_and_restore_off(hass: HomeAssistant) -> None:
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation", "entity_id": "hello.world"},
"action": {"action": "test.automation", "entity_id": "hello.world"},
}
},
)
@@ -1600,7 +1600,7 @@ async def test_automation_is_on_if_no_initial_state_or_restore(
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation", "entity_id": "hello.world"},
"action": {"action": "test.automation", "entity_id": "hello.world"},
}
},
)
@@ -1623,7 +1623,7 @@ async def test_automation_not_trigger_on_bootstrap(hass: HomeAssistant) -> None:
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation", "entity_id": "hello.world"},
"action": {"action": "test.automation", "entity_id": "hello.world"},
}
},
)
@@ -1714,7 +1714,7 @@ async def test_automation_bad_config_validation(
"alias": "good_automation",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"entity_id": "hello.world",
},
},
@@ -1756,7 +1756,7 @@ async def test_automation_bad_config_validation(
"alias": "bad_automation",
"trigger": {"platform": "event", "event_type": "test_event2"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data_template": {"event": "{{ trigger.event.event_type }}"},
},
}
@@ -1785,7 +1785,7 @@ async def test_automation_with_error_in_script(
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation", "entity_id": "hello.world"},
"action": {"action": "test.automation", "entity_id": "hello.world"},
}
},
)
@@ -1811,7 +1811,7 @@ async def test_automation_with_error_in_script_2(
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": None, "entity_id": "hello.world"},
"action": {"action": None, "entity_id": "hello.world"},
}
},
)
@@ -1842,19 +1842,19 @@ async def test_automation_restore_last_triggered_with_initial_state(
"alias": "hello",
"initial_state": "off",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
},
{
"alias": "bye",
"initial_state": "off",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
},
{
"alias": "solong",
"initial_state": "on",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation"},
"action": {"action": "test.automation"},
},
]
}
@@ -2013,11 +2013,11 @@ async def test_extraction_functions(
},
"action": [
{
"service": "test.script",
"action": "test.script",
"data": {"entity_id": "light.in_both"},
},
{
"service": "test.script",
"action": "test.script",
"data": {"entity_id": "light.in_first"},
},
{
@@ -2027,15 +2027,15 @@ async def test_extraction_functions(
"type": "turn_on",
},
{
"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"},
},
],
@@ -2087,7 +2087,7 @@ async def test_extraction_functions(
},
"action": [
{
"service": "test.script",
"action": "test.script",
"data": {"entity_id": "light.in_both"},
},
{
@@ -2140,7 +2140,7 @@ async def test_extraction_functions(
},
"action": [
{
"service": "test.script",
"action": "test.script",
"data": {"entity_id": "light.in_both"},
},
{
@@ -2150,27 +2150,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"},
},
],
@@ -2289,7 +2289,7 @@ async def test_automation_variables(
},
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data": {
"value": "{{ test_var }}",
"event_type": "{{ event_type }}",
@@ -2308,7 +2308,7 @@ async def test_automation_variables(
"value_template": "{{ trigger.event.data.pass_condition }}",
},
"action": {
"service": "test.automation",
"action": "test.automation",
},
},
{
@@ -2317,7 +2317,7 @@ async def test_automation_variables(
},
"trigger": {"platform": "event", "event_type": "test_event_3"},
"action": {
"service": "test.automation",
"action": "test.automation",
},
},
]
@@ -2373,7 +2373,7 @@ async def test_automation_trigger_variables(
},
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data": {
"value": "{{ test_var }}",
"event_type": "{{ event_type }}",
@@ -2391,7 +2391,7 @@ async def test_automation_trigger_variables(
},
"trigger": {"platform": "event", "event_type": "test_event_2"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data": {
"value": "{{ test_var }}",
"event_type": "{{ event_type }}",
@@ -2438,7 +2438,7 @@ async def test_automation_bad_trigger_variables(
},
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
},
},
]
@@ -2465,7 +2465,7 @@ async def test_automation_this_var_always(
{
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data": {
"this_template": "{{this.entity_id}}",
},
@@ -2542,7 +2542,7 @@ async def test_blueprint_automation(
"Blueprint 'Call service based on event' generated invalid automation",
(
"value should be a string for dictionary value @"
" data['action'][0]['service']"
" data['action'][0]['action']"
),
),
],
@@ -2640,7 +2640,7 @@ async def test_trigger_service(hass: HomeAssistant, calls: list[ServiceCall]) ->
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"action": "test.automation",
"data_template": {"trigger": "{{ trigger }}"},
},
}
@@ -2679,14 +2679,14 @@ async def test_trigger_condition_implicit_id(
{
"conditions": {"condition": "trigger", "id": [0, "2"]},
"sequence": {
"service": "test.automation",
"action": "test.automation",
"data": {"param": "one"},
},
},
{
"conditions": {"condition": "trigger", "id": "1"},
"sequence": {
"service": "test.automation",
"action": "test.automation",
"data": {"param": "two"},
},
},
@@ -2730,14 +2730,14 @@ async def test_trigger_condition_explicit_id(
{
"conditions": {"condition": "trigger", "id": "one"},
"sequence": {
"service": "test.automation",
"action": "test.automation",
"data": {"param": "one"},
},
},
{
"conditions": {"condition": "trigger", "id": "two"},
"sequence": {
"service": "test.automation",
"action": "test.automation",
"data": {"param": "two"},
},
},
@@ -2822,8 +2822,8 @@ async def test_recursive_automation_starting_script(
f" {automation_runs} }}}}"
)
},
{"service": "script.script1"},
{"service": "test.script_done"},
{"action": "script.script1"},
{"action": "test.script_done"},
],
},
}
@@ -2840,9 +2840,9 @@ async def test_recursive_automation_starting_script(
{"platform": "event", "event_type": "trigger_automation"},
],
"action": [
{"service": "test.automation_started"},
{"action": "test.automation_started"},
{"delay": 0.001},
{"service": "script.script1"},
{"action": "script.script1"},
],
}
},
@@ -2923,7 +2923,7 @@ async def test_recursive_automation(
],
"action": [
{"event": "trigger_automation"},
{"service": "test.automation_done"},
{"action": "test.automation_done"},
],
}
},
@@ -2985,7 +2985,7 @@ async def test_recursive_automation_restart_mode(
],
"action": [
{"event": "trigger_automation"},
{"service": "test.automation_done"},
{"action": "test.automation_done"},
],
}
},
@@ -3021,7 +3021,7 @@ async def test_websocket_config(
config = {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation", "data": 100},
"action": {"action": "test.automation", "data": 100},
}
assert await async_setup_component(
hass, automation.DOMAIN, {automation.DOMAIN: config}
@@ -3095,7 +3095,7 @@ async def test_automation_turns_off_other_automation(hass: HomeAssistant) -> Non
"from": "on",
},
"action": {
"service": "automation.turn_off",
"action": "automation.turn_off",
"target": {
"entity_id": "automation.automation_1",
},
@@ -3118,7 +3118,7 @@ async def test_automation_turns_off_other_automation(hass: HomeAssistant) -> Non
},
},
"action": {
"service": "persistent_notification.create",
"action": "persistent_notification.create",
"metadata": {},
"data": {
"message": "Test race",
@@ -3185,7 +3185,7 @@ async def test_two_automations_call_restart_script_same_time(
"fire_toggle": {
"sequence": [
{
"service": "input_boolean.toggle",
"action": "input_boolean.toggle",
"target": {"entity_id": "input_boolean.test_1"},
}
]
@@ -3206,7 +3206,7 @@ async def test_two_automations_call_restart_script_same_time(
"to": "on",
},
"action": {
"service": "script.fire_toggle",
"action": "script.fire_toggle",
},
"id": "automation_0",
"mode": "single",
@@ -3218,7 +3218,7 @@ async def test_two_automations_call_restart_script_same_time(
"to": "on",
},
"action": {
"service": "script.fire_toggle",
"action": "script.fire_toggle",
},
"id": "automation_1",
"mode": "single",
@@ -3301,3 +3301,29 @@ async def test_two_automation_call_restart_script_right_after_each_other(
hass.states.async_set("input_boolean.test_2", "on")
await hass.async_block_till_done()
assert len(events) == 1
async def test_action_service_backward_compatibility(
hass: HomeAssistant, calls: list[ServiceCall]
) -> None:
"""Test we can still use the service call method."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {
"service": "test.automation",
"entity_id": "hello.world",
"data": {"event": "{{ trigger.event.event_type }}"},
},
}
},
)
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data.get(ATTR_ENTITY_ID) == ["hello.world"]
assert calls[0].data.get("event") == "test_event"