diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index 93abd6ca4e4b7f11ddce100eb79cdcc3c41b539a..c2d221bcc78c5cfa6c6d87f18ea9de87a56a6d30 100644 --- a/homeassistant/helpers/selector.py +++ b/homeassistant/helpers/selector.py @@ -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.""" diff --git a/tests/helpers/test_selector.py b/tests/helpers/test_selector.py index c809eaea8bd94ce5a43540ce91c23a0a4a1a1612..5472e6609f0672b7bcc638d5000587e5248c7e20 100644 --- a/tests/helpers/test_selector.py +++ b/tests/helpers/test_selector.py @@ -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)),),