mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add config entry selector (#77108)
This commit is contained in:
parent
f1075644f8
commit
dc17bca00c
@ -318,6 +318,34 @@ class ColorTempSelector(Selector):
|
||||
return value
|
||||
|
||||
|
||||
class ConfigEntrySelectorConfig(TypedDict, total=False):
|
||||
"""Class to represent a config entry selector config."""
|
||||
|
||||
integration: str
|
||||
|
||||
|
||||
@SELECTORS.register("config_entry")
|
||||
class ConfigEntrySelector(Selector):
|
||||
"""Selector of a config entry."""
|
||||
|
||||
selector_type = "config_entry"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional("integration"): str,
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(self, config: ConfigEntrySelectorConfig | None = None) -> None:
|
||||
"""Instantiate a selector."""
|
||||
super().__init__(config)
|
||||
|
||||
def __call__(self, data: Any) -> dict[str, str]:
|
||||
"""Validate the passed selection."""
|
||||
config: dict[str, str] = vol.Schema(str)(data)
|
||||
return config
|
||||
|
||||
|
||||
class DateSelectorConfig(TypedDict):
|
||||
"""Class to represent a date selector config."""
|
||||
|
||||
|
@ -285,6 +285,26 @@ def test_boolean_selector_schema(schema, valid_selections, invalid_selections):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"schema,valid_selections,invalid_selections",
|
||||
(
|
||||
(
|
||||
{},
|
||||
("6b68b250388cbe0d620c92dd3acc93ec", "76f2e8f9a6491a1b580b3a8967c27ddd"),
|
||||
(None, True, 1),
|
||||
),
|
||||
(
|
||||
{"integration": "adguard"},
|
||||
("6b68b250388cbe0d620c92dd3acc93ec", "76f2e8f9a6491a1b580b3a8967c27ddd"),
|
||||
(None, True, 1),
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_config_entry_selector_schema(schema, valid_selections, invalid_selections):
|
||||
"""Test boolean selector."""
|
||||
_test_selector("config_entry", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"schema,valid_selections,invalid_selections",
|
||||
(({}, ("00:00:00",), ("blah", None)),),
|
||||
|
Loading…
x
Reference in New Issue
Block a user