mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add Template selector (#70229)
This commit is contained in:
parent
1e4aacaeb1
commit
ce1f074ca9
@ -765,6 +765,28 @@ class TargetSelector(Selector):
|
||||
return target
|
||||
|
||||
|
||||
class TemplateSelectorConfig(TypedDict):
|
||||
"""Class to represent an template selector config."""
|
||||
|
||||
|
||||
@SELECTORS.register("template")
|
||||
class TemplateSelector(Selector):
|
||||
"""Selector for an template."""
|
||||
|
||||
selector_type = "template"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({})
|
||||
|
||||
def __init__(self, config: TemplateSelectorConfig | None = None) -> None:
|
||||
"""Instantiate a selector."""
|
||||
super().__init__(config)
|
||||
|
||||
def __call__(self, data: Any) -> str:
|
||||
"""Validate the passed selection."""
|
||||
template = cv.template(data)
|
||||
return template.template
|
||||
|
||||
|
||||
class TextSelectorConfig(TypedDict, total=False):
|
||||
"""Class to represent a text selector config."""
|
||||
|
||||
|
@ -627,3 +627,12 @@ def test_datetime_selector_schema(schema, valid_selections, invalid_selections):
|
||||
"""Test datetime selector."""
|
||||
|
||||
_test_selector("datetime", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"schema,valid_selections,invalid_selections",
|
||||
(({}, ("abc123", "{{ now() }}"), (None, "{{ incomplete }", "{% if True %}Hi!")),),
|
||||
)
|
||||
def test_template_selector_schema(schema, valid_selections, invalid_selections):
|
||||
"""Test template selector."""
|
||||
_test_selector("template", schema, valid_selections, invalid_selections)
|
||||
|
Loading…
x
Reference in New Issue
Block a user