From bb8036f2c87301b7ecada99ee0da7bccdb424813 Mon Sep 17 00:00:00 2001 From: Wendelin <12148533+wendevlin@users.noreply.github.com> Date: Wed, 3 Jun 2026 10:12:52 +0200 Subject: [PATCH] Automation choose: Add optional note to options (#172837) --- homeassistant/helpers/config_validation.py | 1 + tests/helpers/test_config_validation.py | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 46096f6f2b87..6034ede44498 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -1953,6 +1953,7 @@ _SCRIPT_CHOOSE_SCHEMA = vol.Schema( [ { vol.Optional(CONF_ALIAS): string, + vol.Remove(CONF_NOTE): str, # Is only used in frontend vol.Required(CONF_CONDITIONS): CONDITIONS_SCHEMA, vol.Required(CONF_SEQUENCE): SCRIPT_SCHEMA, } diff --git a/tests/helpers/test_config_validation.py b/tests/helpers/test_config_validation.py index e6a9c1bf5ddb..f30b9d2b838c 100644 --- a/tests/helpers/test_config_validation.py +++ b/tests/helpers/test_config_validation.py @@ -2084,3 +2084,39 @@ def test_base_schemas_reject_invalid_note( """Test that script, condition, trigger base schemas reject non-string notes.""" with pytest.raises(vol.Invalid): validator({**base_config, "note": invalid_note}) + + +_CHOOSE_OPTION_BASE_CONFIG = { + "conditions": [ + {"condition": "state", "entity_id": "sun.sun", "state": "above_horizon"} + ], + "sequence": [{"action": "test.foo"}], +} + + +@pytest.mark.usefixtures("hass") +def test_choose_option_accepts_note() -> None: + """Test that the note field is accepted and stripped from a choose option.""" + validated = cv.script_action( + {"choose": [{**_CHOOSE_OPTION_BASE_CONFIG, "note": "Single line"}]} + ) + assert "note" not in validated["choose"][0] + + +@pytest.mark.parametrize( + "invalid_note", + [ + pytest.param(None, id="none"), + pytest.param(42, id="int"), + pytest.param(True, id="bool"), + pytest.param([], id="list"), + pytest.param({}, id="dict"), + ], +) +@pytest.mark.usefixtures("hass") +def test_choose_option_rejects_invalid_note(invalid_note: Any) -> None: + """Test that choose option schemas reject non-string notes.""" + with pytest.raises(vol.Invalid): + cv.script_action( + {"choose": [{**_CHOOSE_OPTION_BASE_CONFIG, "note": invalid_note}]} + )