Add condition selector for blueprint (#96350)

* Add condition selector for blueprint

* Add tests and validation

* Update comment
This commit is contained in:
Paul Bottein 2023-07-12 16:58:35 +02:00 committed by GitHub
parent e8c2921852
commit e513b7d0eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -453,6 +453,27 @@ class ColorTempSelector(Selector[ColorTempSelectorConfig]):
return value
class ConditionSelectorConfig(TypedDict):
"""Class to represent an action selector config."""
@SELECTORS.register("condition")
class ConditionSelector(Selector[ConditionSelectorConfig]):
"""Selector of an condition sequence (script syntax)."""
selector_type = "condition"
CONFIG_SCHEMA = vol.Schema({})
def __init__(self, config: ConditionSelectorConfig | None = None) -> None:
"""Instantiate a selector."""
super().__init__(config)
def __call__(self, data: Any) -> Any:
"""Validate the passed selection."""
return vol.Schema(cv.CONDITIONS_SCHEMA)(data)
class ConfigEntrySelectorConfig(TypedDict, total=False):
"""Class to represent a config entry selector config."""

View File

@ -1017,3 +1017,29 @@ def test_conversation_agent_selector_schema(
) -> None:
"""Test conversation agent selector."""
_test_selector("conversation_agent", schema, valid_selections, invalid_selections)
@pytest.mark.parametrize(
("schema", "valid_selections", "invalid_selections"),
(
(
{},
(
[
{
"condition": "numeric_state",
"entity_id": ["sensor.temperature"],
"below": 20,
}
],
[],
),
("abc"),
),
),
)
def test_condition_selector_schema(
schema, valid_selections, invalid_selections
) -> None:
"""Test condition sequence selector."""
_test_selector("condition", schema, valid_selections, invalid_selections)