1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-08 17:49:37 +01:00

use mode instead

This commit is contained in:
Bram Kragten
2026-03-25 15:59:13 +01:00
parent 6b61984342
commit 5f6b60cb78
62 changed files with 90 additions and 229 deletions
@@ -6,9 +6,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
# --- Number or entity selectors ---
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
.number_or_entity_co: &number_or_entity_co
required: false
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_armed: *condition_common
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
armed: *trigger_common
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_idle: *condition_common
is_listening: *condition_common
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
idle: *trigger_common
listening: *trigger_common
@@ -10,9 +10,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
.number_or_entity: &number_or_entity
required: false
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
.number_or_entity_humidity: &number_or_entity_humidity
required: false
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
.number_or_entity_humidity: &number_or_entity_humidity
required: false
@@ -5,9 +5,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
awning_is_closed:
fields: *condition_common_fields
+1 -4
View File
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
awning_closed:
fields: *trigger_common_fields
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_home: *condition_common
is_not_home: *condition_common
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
entered_home: *trigger_common
left_home: *trigger_common
@@ -5,9 +5,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_closed:
fields: *condition_common_fields
+1 -4
View File
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
closed:
fields: *trigger_common_fields
+1 -3
View File
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_off: *condition_common
is_on: *condition_common
+1 -4
View File
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
turned_on: *trigger_common
turned_off: *trigger_common
@@ -5,9 +5,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_closed:
fields: *condition_common_fields
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
closed:
fields: *trigger_common_fields
@@ -5,9 +5,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_closed:
fields: *condition_common_fields
+1 -4
View File
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
closed:
fields: *trigger_common_fields
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
.number_or_entity: &number_or_entity
required: false
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
started_drying: *trigger_common
started_humidifying: *trigger_common
@@ -36,8 +36,6 @@ is_value:
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
above: *number_or_entity
below: *number_or_entity
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
.number_or_entity: &number_or_entity
required: false
@@ -10,9 +10,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
.number_or_entity: &number_or_entity
required: false
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
.number_or_entity: &number_or_entity
required: false
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_docked: *condition_common
is_encountering_an_error: *condition_common
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
docked: *trigger_common
errored: *trigger_common
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_off: *condition_common
is_on: *condition_common
+1 -4
View File
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
.number_or_entity: &number_or_entity
required: false
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_jammed: *condition_common
is_locked: *condition_common
+1 -4
View File
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
jammed: *trigger_common
locked: *trigger_common
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_off: *condition_common
is_on: *condition_common
@@ -9,7 +9,4 @@ stopped_playing:
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
.number_or_entity: &number_or_entity
required: false
@@ -5,9 +5,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_detected:
fields: *condition_common_fields
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
detected:
fields: *trigger_common_fields
@@ -5,9 +5,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_detected:
fields: *condition_common_fields
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
detected:
fields: *trigger_common_fields
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_home: *condition_common
is_not_home: *condition_common
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
entered_home: *trigger_common
left_home: *trigger_common
@@ -53,9 +53,7 @@ is_value:
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
above: *number_or_entity_power
below: *number_or_entity_power
unit: *condition_unit_power
+1 -4
View File
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
.number_or_entity: &number_or_entity
required: false
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
turned_off: *trigger_common
turned_on: *trigger_common
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_off: *condition_common
is_on: *condition_common
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
turned_off: *trigger_common
turned_on: *trigger_common
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_off: *condition_common
is_on: *condition_common
+1 -4
View File
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
turned_off: *trigger_common
turned_on: *trigger_common
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_off: *condition_common
is_on: *condition_common
@@ -10,10 +10,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
turned_off: *trigger_common
turned_on: *trigger_common
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
.number_or_entity: &number_or_entity
required: false
@@ -10,9 +10,7 @@ is_equal_to:
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
value:
required: true
selector:
@@ -9,9 +9,6 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
update_became_available: *trigger_common
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_cleaning: *condition_common
is_docked: *condition_common
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
docked: *trigger_common
errored: *trigger_common
@@ -9,9 +9,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
.number_or_entity_temperature: &number_or_entity_temperature
required: false
@@ -9,10 +9,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
.trigger_threshold_type: &trigger_threshold_type
required: true
@@ -5,9 +5,7 @@
selector:
automation_behavior:
translation_key: condition_behavior
behavior:
- all
- any
mode: condition
is_closed:
fields: *condition_common_fields
@@ -5,10 +5,7 @@
selector:
automation_behavior:
translation_key: trigger_behavior
behavior:
- first
- last
- any
mode: trigger
closed:
fields: *trigger_common_fields
+25 -10
View File
@@ -252,11 +252,31 @@ class AutomationBehavior(StrEnum):
ANY = "any"
class AutomationBehaviorSelectorMode(StrEnum):
"""Possible modes for an automation behavior selector."""
TRIGGER = "trigger"
CONDITION = "condition"
_AUTOMATION_BEHAVIOR_MODES: dict[AutomationBehaviorSelectorMode, list[str]] = {
AutomationBehaviorSelectorMode.TRIGGER: [
AutomationBehavior.FIRST,
AutomationBehavior.LAST,
AutomationBehavior.ANY,
],
AutomationBehaviorSelectorMode.CONDITION: [
AutomationBehavior.ALL,
AutomationBehavior.ANY,
],
}
class AutomationBehaviorConfig(BaseSelectorConfig, total=False):
"""Class to represent an automation behavior selector config."""
mode: Required[AutomationBehaviorSelectorMode]
translation_key: str
behavior: list[str]
@SELECTORS.register("automation_behavior")
@@ -267,9 +287,8 @@ class AutomationBehaviorSelector(Selector[AutomationBehaviorConfig]):
CONFIG_SCHEMA = make_selector_config_schema(
{
vol.Optional("behavior"): vol.All(
cv.ensure_list,
[vol.All(vol.Coerce(AutomationBehavior), lambda val: val.value)],
vol.Required("mode"): vol.All(
vol.Coerce(AutomationBehaviorSelectorMode), lambda val: val.value
),
vol.Optional("translation_key"): cv.string,
},
@@ -283,12 +302,8 @@ class AutomationBehaviorSelector(Selector[AutomationBehaviorConfig]):
"""Validate the passed selection."""
if not isinstance(data, str):
raise vol.Invalid("Value should be a string")
allowed = self.config.get("behavior") or [
AutomationBehavior.FIRST,
AutomationBehavior.LAST,
AutomationBehavior.ANY,
]
return vol.In(allowed)(data)
mode = AutomationBehaviorSelectorMode(self.config["mode"])
return vol.In(_AUTOMATION_BEHAVIOR_MODES[mode])(data)
class ActionSelectorConfig(BaseSelectorConfig):
+5 -8
View File
@@ -1187,20 +1187,17 @@ def test_action_selector_schema(schema, valid_selections, invalid_selections) ->
("schema", "valid_selections", "invalid_selections"),
[
(
{},
{"mode": "trigger"},
("first", "last", "any"),
("all", "invalid", None),
),
(
{"behavior": ["all", "any"]},
{"mode": "condition"},
("all", "any"),
("first", "last", "invalid", None),
),
(
{
"behavior": ["first", "last", "any"],
"translation_key": "trigger_behavior",
},
{"mode": "trigger", "translation_key": "trigger_behavior"},
("first", "last", "any"),
("all", "invalid", None),
),
@@ -1216,8 +1213,8 @@ def test_automation_behavior_selector_schema(
@pytest.mark.parametrize(
"schema",
[
{"behavior": ["invalid_behavior"]},
{"behavior": ["first", "invalid"]},
{},
{"mode": "invalid_mode"},
],
)
def test_automation_behavior_selector_schema_error(schema) -> None: