Add assist pipeline and language selectors (#92030)
parent
f6d8859dd2
commit
aa4544accb
|
@ -286,6 +286,28 @@ class AreaSelector(Selector[AreaSelectorConfig]):
|
|||
return [vol.Schema(str)(val) for val in data]
|
||||
|
||||
|
||||
class AssistPipelineSelectorConfig(TypedDict, total=False):
|
||||
"""Class to represent an assist pipeline selector config."""
|
||||
|
||||
|
||||
@SELECTORS.register("assist_pipeline")
|
||||
class AssistPipelineSelector(Selector[AssistPipelineSelectorConfig]):
|
||||
"""Selector for an assist pipeline."""
|
||||
|
||||
selector_type = "assist_pipeline"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({})
|
||||
|
||||
def __init__(self, config: AssistPipelineSelectorConfig) -> None:
|
||||
"""Instantiate a selector."""
|
||||
super().__init__(config)
|
||||
|
||||
def __call__(self, data: Any) -> str:
|
||||
"""Validate the passed selection."""
|
||||
pipeline: str = vol.Schema(str)(data)
|
||||
return pipeline
|
||||
|
||||
|
||||
class AttributeSelectorConfig(TypedDict, total=False):
|
||||
"""Class to represent an attribute selector config."""
|
||||
|
||||
|
@ -659,6 +681,40 @@ class IconSelector(Selector[IconSelectorConfig]):
|
|||
return icon
|
||||
|
||||
|
||||
class LanguageSelectorConfig(TypedDict, total=False):
|
||||
"""Class to represent an language selector config."""
|
||||
|
||||
languages: list[str]
|
||||
native_name: bool
|
||||
no_sort: bool
|
||||
|
||||
|
||||
@SELECTORS.register("language")
|
||||
class LanguageSelector(Selector[LanguageSelectorConfig]):
|
||||
"""Selector for an language."""
|
||||
|
||||
selector_type = "language"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional("languages"): [str],
|
||||
vol.Optional("native_name", default=False): cv.boolean,
|
||||
vol.Optional("no_sort", default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(self, config: LanguageSelectorConfig) -> None:
|
||||
"""Instantiate a selector."""
|
||||
super().__init__(config)
|
||||
|
||||
def __call__(self, data: Any) -> str:
|
||||
"""Validate the passed selection."""
|
||||
language: str = vol.Schema(str)(data)
|
||||
if "languages" in self.config and language not in self.config["languages"]:
|
||||
raise vol.Invalid(f"Value {language} is not a valid option")
|
||||
return language
|
||||
|
||||
|
||||
class LocationSelectorConfig(TypedDict, total=False):
|
||||
"""Class to represent a location selector config."""
|
||||
|
||||
|
|
|
@ -342,6 +342,23 @@ def test_area_selector_schema(schema, valid_selections, invalid_selections) -> N
|
|||
_test_selector("area", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("schema", "valid_selections", "invalid_selections"),
|
||||
(
|
||||
(
|
||||
{},
|
||||
("23ouih2iu23ou2", "2j4hp3uy4p87wyrpiuhk34"),
|
||||
(None, True, 1),
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_assist_pipeline_selector_schema(
|
||||
schema, valid_selections, invalid_selections
|
||||
) -> None:
|
||||
"""Test assist pipeline selector."""
|
||||
_test_selector("assist_pipeline", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("schema", "valid_selections", "invalid_selections"),
|
||||
(
|
||||
|
@ -431,7 +448,7 @@ def test_boolean_selector_schema(schema, valid_selections, invalid_selections) -
|
|||
def test_config_entry_selector_schema(
|
||||
schema, valid_selections, invalid_selections
|
||||
) -> None:
|
||||
"""Test boolean selector."""
|
||||
"""Test config entry selector."""
|
||||
_test_selector("config_entry", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
|
@ -748,6 +765,26 @@ def test_media_selector_schema(schema, valid_selections, invalid_selections) ->
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("schema", "valid_selections", "invalid_selections"),
|
||||
(
|
||||
(
|
||||
{},
|
||||
("nl", "fr"),
|
||||
(None, True, 1),
|
||||
),
|
||||
(
|
||||
{"languages": ["nl", "fr"]},
|
||||
("nl", "fr"),
|
||||
(None, True, 1, "de", "en"),
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_language_selector_schema(schema, valid_selections, invalid_selections) -> None:
|
||||
"""Test language selector."""
|
||||
_test_selector("language", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("schema", "valid_selections", "invalid_selections"),
|
||||
(
|
||||
|
|
Loading…
Reference in New Issue