1
mirror of https://github.com/home-assistant/core synced 2024-09-09 12:51:22 +02:00

Add config entry selector (#77108)

This commit is contained in:
Franck Nijhof 2022-08-24 00:29:30 +02:00 committed by GitHub
parent f1075644f8
commit dc17bca00c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

View File

@ -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."""

View File

@ -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)),),