mirror of
https://github.com/home-assistant/core.git
synced 2026-07-10 00:05:13 +01:00
Automation choose: Add optional note to options (#172837)
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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}]}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user