diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index b48ffb6e964..68511a771d3 100644 --- a/homeassistant/helpers/selector.py +++ b/homeassistant/helpers/selector.py @@ -176,3 +176,12 @@ class StringSelector(Selector): """Selector for a multi-line text string.""" CONFIG_SCHEMA = vol.Schema({vol.Optional("multiline", default=False): bool}) + + +@SELECTORS.register("select") +class SelectSelector(Selector): + """Selector for an single-choice input select.""" + + CONFIG_SCHEMA = vol.Schema( + {vol.Required("options"): vol.All([str], vol.Length(min=1))} + ) diff --git a/tests/helpers/test_selector.py b/tests/helpers/test_selector.py index 2916d616703..c43ed4097e0 100644 --- a/tests/helpers/test_selector.py +++ b/tests/helpers/test_selector.py @@ -187,3 +187,26 @@ def test_object_selector_schema(schema): def test_text_selector_schema(schema): """Test text selector.""" selector.validate_selector({"text": schema}) + + +@pytest.mark.parametrize( + "schema", + ({"options": ["red", "green", "blue"]},), +) +def test_select_selector_schema(schema): + """Test select selector.""" + selector.validate_selector({"select": schema}) + + +@pytest.mark.parametrize( + "schema", + ( + {}, + {"options": {"hello": "World"}}, + {"options": []}, + ), +) +def test_select_selector_schema_error(schema): + """Test select selector.""" + with pytest.raises(vol.Invalid): + selector.validate_selector({"select": schema})