mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Add condition selector for blueprint (#96350)
* Add condition selector for blueprint * Add tests and validation * Update comment
This commit is contained in:
parent
e8c2921852
commit
e513b7d0eb
@ -453,6 +453,27 @@ class ColorTempSelector(Selector[ColorTempSelectorConfig]):
|
|||||||
return value
|
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 ConfigEntrySelectorConfig(TypedDict, total=False):
|
||||||
"""Class to represent a config entry selector config."""
|
"""Class to represent a config entry selector config."""
|
||||||
|
|
||||||
|
@ -1017,3 +1017,29 @@ def test_conversation_agent_selector_schema(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test conversation agent selector."""
|
"""Test conversation agent selector."""
|
||||||
_test_selector("conversation_agent", schema, valid_selections, invalid_selections)
|
_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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user