Add trigger selector for blueprint (#103050)
This commit is contained in:
parent
f5cc4dcf3e
commit
89a9e6c6e8
2 changed files with 46 additions and 1 deletions
|
@ -459,7 +459,7 @@ class ColorTempSelector(Selector[ColorTempSelectorConfig]):
|
|||
|
||||
|
||||
class ConditionSelectorConfig(TypedDict):
|
||||
"""Class to represent an action selector config."""
|
||||
"""Class to represent an condition selector config."""
|
||||
|
||||
|
||||
@SELECTORS.register("condition")
|
||||
|
@ -1280,6 +1280,27 @@ class TimeSelector(Selector[TimeSelectorConfig]):
|
|||
return cast(str, data)
|
||||
|
||||
|
||||
class TriggerSelectorConfig(TypedDict):
|
||||
"""Class to represent an trigger selector config."""
|
||||
|
||||
|
||||
@SELECTORS.register("trigger")
|
||||
class TriggerSelector(Selector[TriggerSelectorConfig]):
|
||||
"""Selector of a trigger sequence (script syntax)."""
|
||||
|
||||
selector_type = "trigger"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({})
|
||||
|
||||
def __init__(self, config: TriggerSelectorConfig | None = None) -> None:
|
||||
"""Instantiate a selector."""
|
||||
super().__init__(config)
|
||||
|
||||
def __call__(self, data: Any) -> Any:
|
||||
"""Validate the passed selection."""
|
||||
return vol.Schema(cv.TRIGGER_SCHEMA)(data)
|
||||
|
||||
|
||||
class FileSelectorConfig(TypedDict):
|
||||
"""Class to represent a file selector config."""
|
||||
|
||||
|
|
|
@ -1074,3 +1074,27 @@ def test_condition_selector_schema(
|
|||
) -> None:
|
||||
"""Test condition sequence selector."""
|
||||
_test_selector("condition", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("schema", "valid_selections", "invalid_selections"),
|
||||
(
|
||||
(
|
||||
{},
|
||||
(
|
||||
[
|
||||
{
|
||||
"platform": "numeric_state",
|
||||
"entity_id": ["sensor.temperature"],
|
||||
"below": 20,
|
||||
}
|
||||
],
|
||||
[],
|
||||
),
|
||||
("abc"),
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_trigger_selector_schema(schema, valid_selections, invalid_selections) -> None:
|
||||
"""Test trigger sequence selector."""
|
||||
_test_selector("trigger", schema, valid_selections, invalid_selections)
|
||||
|
|
Loading…
Add table
Reference in a new issue