From 72a35231938d79bed601203c38eeb33af935d0c3 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Fri, 9 Jan 2026 11:43:33 +0100 Subject: [PATCH] Fix trigger selectors (#160519) --- .../components/climate/triggers.yaml | 9 ++-- .../components/humidifier/triggers.yaml | 9 ++-- homeassistant/components/light/triggers.yaml | 9 ++-- homeassistant/helpers/trigger.py | 2 +- tests/helpers/test_trigger.py | 50 +++++++++---------- 5 files changed, 41 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/climate/triggers.yaml b/homeassistant/components/climate/triggers.yaml index 0614e0ccd36..6dc7c59b81a 100644 --- a/homeassistant/components/climate/triggers.yaml +++ b/homeassistant/components/climate/triggers.yaml @@ -19,6 +19,10 @@ selector: choose: choices: + number: + selector: + number: + mode: box entity: selector: entity: @@ -27,14 +31,11 @@ - input_number - number - sensor - number: - selector: - number: - mode: box translation_key: number_or_entity .trigger_threshold_type: &trigger_threshold_type required: true + default: above selector: select: options: diff --git a/homeassistant/components/humidifier/triggers.yaml b/homeassistant/components/humidifier/triggers.yaml index ea58ece9698..23e8986ba6b 100644 --- a/homeassistant/components/humidifier/triggers.yaml +++ b/homeassistant/components/humidifier/triggers.yaml @@ -19,6 +19,10 @@ selector: choose: choices: + number: + selector: + number: + mode: box entity: selector: entity: @@ -27,14 +31,11 @@ - input_number - number - sensor - number: - selector: - number: - mode: box translation_key: number_or_entity .trigger_threshold_type: &trigger_threshold_type required: true + default: above selector: select: options: diff --git a/homeassistant/components/light/triggers.yaml b/homeassistant/components/light/triggers.yaml index 87f720d6404..75843ea1a53 100644 --- a/homeassistant/components/light/triggers.yaml +++ b/homeassistant/components/light/triggers.yaml @@ -19,6 +19,10 @@ selector: choose: choices: + number: + selector: + number: + mode: box entity: selector: entity: @@ -27,10 +31,6 @@ - input_number - number - sensor - number: - selector: - number: - mode: box translation_key: number_or_entity turned_on: *trigger_common @@ -48,6 +48,7 @@ brightness_crossed_threshold: behavior: *trigger_behavior threshold_type: required: true + default: above selector: select: options: diff --git a/homeassistant/helpers/trigger.py b/homeassistant/helpers/trigger.py index bffc01ecfd7..baa0e379de0 100644 --- a/homeassistant/helpers/trigger.py +++ b/homeassistant/helpers/trigger.py @@ -683,7 +683,7 @@ NUMERICAL_ATTRIBUTE_CROSSED_THRESHOLD_SCHEMA = ENTITY_STATE_TRIGGER_SCHEMA.exten ), vol.Optional(CONF_LOWER_LIMIT): _number_or_entity, vol.Optional(CONF_UPPER_LIMIT): _number_or_entity, - vol.Required(CONF_THRESHOLD_TYPE): ThresholdType, + vol.Required(CONF_THRESHOLD_TYPE): vol.Coerce(ThresholdType), }, _validate_range(CONF_LOWER_LIMIT, CONF_UPPER_LIMIT), _validate_limits_for_threshold_type, diff --git a/tests/helpers/test_trigger.py b/tests/helpers/test_trigger.py index 0d1400bcbd1..092ae05d96a 100644 --- a/tests/helpers/test_trigger.py +++ b/tests/helpers/test_trigger.py @@ -40,7 +40,6 @@ from homeassistant.helpers.trigger import ( CONF_UPPER_LIMIT, DATA_PLUGGABLE_ACTIONS, PluggableAction, - ThresholdType, Trigger, TriggerActionRunner, _async_get_trigger_platform, @@ -1387,25 +1386,26 @@ async def test_numerical_state_attribute_changed_error_handling( ("trigger_options", "expected_result"), [ # Valid configurations + # Don't use the enum in tests to allow testing validation of strings when the source is JSON or YAML ( - {CONF_THRESHOLD_TYPE: ThresholdType.ABOVE, CONF_LOWER_LIMIT: 10}, + {CONF_THRESHOLD_TYPE: "above", CONF_LOWER_LIMIT: 10}, does_not_raise(), ), ( - {CONF_THRESHOLD_TYPE: ThresholdType.ABOVE, CONF_LOWER_LIMIT: "sensor.test"}, + {CONF_THRESHOLD_TYPE: "above", CONF_LOWER_LIMIT: "sensor.test"}, does_not_raise(), ), ( - {CONF_THRESHOLD_TYPE: ThresholdType.BELOW, CONF_UPPER_LIMIT: 90}, + {CONF_THRESHOLD_TYPE: "below", CONF_UPPER_LIMIT: 90}, does_not_raise(), ), ( - {CONF_THRESHOLD_TYPE: ThresholdType.BELOW, CONF_UPPER_LIMIT: "sensor.test"}, + {CONF_THRESHOLD_TYPE: "below", CONF_UPPER_LIMIT: "sensor.test"}, does_not_raise(), ), ( { - CONF_THRESHOLD_TYPE: ThresholdType.BETWEEN, + CONF_THRESHOLD_TYPE: "between", CONF_LOWER_LIMIT: 10, CONF_UPPER_LIMIT: 90, }, @@ -1413,7 +1413,7 @@ async def test_numerical_state_attribute_changed_error_handling( ), ( { - CONF_THRESHOLD_TYPE: ThresholdType.BETWEEN, + CONF_THRESHOLD_TYPE: "between", CONF_LOWER_LIMIT: 10, CONF_UPPER_LIMIT: "sensor.test", }, @@ -1421,7 +1421,7 @@ async def test_numerical_state_attribute_changed_error_handling( ), ( { - CONF_THRESHOLD_TYPE: ThresholdType.BETWEEN, + CONF_THRESHOLD_TYPE: "between", CONF_LOWER_LIMIT: "sensor.test", CONF_UPPER_LIMIT: 90, }, @@ -1429,7 +1429,7 @@ async def test_numerical_state_attribute_changed_error_handling( ), ( { - CONF_THRESHOLD_TYPE: ThresholdType.BETWEEN, + CONF_THRESHOLD_TYPE: "between", CONF_LOWER_LIMIT: "sensor.test", CONF_UPPER_LIMIT: "sensor.test", }, @@ -1437,7 +1437,7 @@ async def test_numerical_state_attribute_changed_error_handling( ), ( { - CONF_THRESHOLD_TYPE: ThresholdType.OUTSIDE, + CONF_THRESHOLD_TYPE: "outside", CONF_LOWER_LIMIT: 10, CONF_UPPER_LIMIT: 90, }, @@ -1445,7 +1445,7 @@ async def test_numerical_state_attribute_changed_error_handling( ), ( { - CONF_THRESHOLD_TYPE: ThresholdType.OUTSIDE, + CONF_THRESHOLD_TYPE: "outside", CONF_LOWER_LIMIT: 10, CONF_UPPER_LIMIT: "sensor.test", }, @@ -1453,7 +1453,7 @@ async def test_numerical_state_attribute_changed_error_handling( ), ( { - CONF_THRESHOLD_TYPE: ThresholdType.OUTSIDE, + CONF_THRESHOLD_TYPE: "outside", CONF_LOWER_LIMIT: "sensor.test", CONF_UPPER_LIMIT: 90, }, @@ -1461,7 +1461,7 @@ async def test_numerical_state_attribute_changed_error_handling( ), ( { - CONF_THRESHOLD_TYPE: ThresholdType.OUTSIDE, + CONF_THRESHOLD_TYPE: "outside", CONF_LOWER_LIMIT: "sensor.test", CONF_UPPER_LIMIT: "sensor.test", }, @@ -1481,58 +1481,58 @@ async def test_numerical_state_attribute_changed_error_handling( ), ( # Must provide lower limit for ABOVE - {CONF_THRESHOLD_TYPE: ThresholdType.ABOVE}, + {CONF_THRESHOLD_TYPE: "above"}, pytest.raises(vol.Invalid), ), ( # Must provide lower limit for ABOVE - {CONF_THRESHOLD_TYPE: ThresholdType.ABOVE, CONF_UPPER_LIMIT: 90}, + {CONF_THRESHOLD_TYPE: "above", CONF_UPPER_LIMIT: 90}, pytest.raises(vol.Invalid), ), ( # Must provide upper limit for BELOW - {CONF_THRESHOLD_TYPE: ThresholdType.BELOW}, + {CONF_THRESHOLD_TYPE: "below"}, pytest.raises(vol.Invalid), ), ( # Must provide upper limit for BELOW - {CONF_THRESHOLD_TYPE: ThresholdType.BELOW, CONF_LOWER_LIMIT: 10}, + {CONF_THRESHOLD_TYPE: "below", CONF_LOWER_LIMIT: 10}, pytest.raises(vol.Invalid), ), ( # Must provide upper and lower limits for BETWEEN - {CONF_THRESHOLD_TYPE: ThresholdType.BETWEEN}, + {CONF_THRESHOLD_TYPE: "between"}, pytest.raises(vol.Invalid), ), ( # Must provide upper and lower limits for BETWEEN - {CONF_THRESHOLD_TYPE: ThresholdType.BETWEEN, CONF_LOWER_LIMIT: 10}, + {CONF_THRESHOLD_TYPE: "between", CONF_LOWER_LIMIT: 10}, pytest.raises(vol.Invalid), ), ( # Must provide upper and lower limits for BETWEEN - {CONF_THRESHOLD_TYPE: ThresholdType.BETWEEN, CONF_UPPER_LIMIT: 90}, + {CONF_THRESHOLD_TYPE: "between", CONF_UPPER_LIMIT: 90}, pytest.raises(vol.Invalid), ), ( # Must provide upper and lower limits for OUTSIDE - {CONF_THRESHOLD_TYPE: ThresholdType.OUTSIDE}, + {CONF_THRESHOLD_TYPE: "outside"}, pytest.raises(vol.Invalid), ), ( # Must provide upper and lower limits for OUTSIDE - {CONF_THRESHOLD_TYPE: ThresholdType.OUTSIDE, CONF_LOWER_LIMIT: 10}, + {CONF_THRESHOLD_TYPE: "outside", CONF_LOWER_LIMIT: 10}, pytest.raises(vol.Invalid), ), ( # Must provide upper and lower limits for OUTSIDE - {CONF_THRESHOLD_TYPE: ThresholdType.OUTSIDE, CONF_UPPER_LIMIT: 90}, + {CONF_THRESHOLD_TYPE: "outside", CONF_UPPER_LIMIT: 90}, pytest.raises(vol.Invalid), ), ( # Must be valid entity id { - CONF_THRESHOLD_TYPE: ThresholdType.BETWEEN, + CONF_THRESHOLD_TYPE: "between", CONF_ABOVE: "cat", CONF_BELOW: "dog", }, @@ -1541,7 +1541,7 @@ async def test_numerical_state_attribute_changed_error_handling( ( # Above must be smaller than below { - CONF_THRESHOLD_TYPE: ThresholdType.BETWEEN, + CONF_THRESHOLD_TYPE: "between", CONF_ABOVE: 90, CONF_BELOW: 10, },