From 5dcbb634f66aa0fbd2ac4c669c32906b8132ce0b Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 19 Nov 2020 16:48:43 +0100 Subject: [PATCH] Fix selector to return the selector type (#43395) --- homeassistant/helpers/selector.py | 8 +++++--- tests/helpers/test_selector.py | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index 9f049e07213..b00ae972c8e 100644 --- a/homeassistant/helpers/selector.py +++ b/homeassistant/helpers/selector.py @@ -18,12 +18,14 @@ def validate_selector(config: Any) -> Dict: selector_type = list(config)[0] - seslector_class = SELECTORS.get(selector_type) + selector_class = SELECTORS.get(selector_type) - if seslector_class is None: + if selector_class is None: raise vol.Invalid(f"Unknown selector type {selector_type} found") - return cast(Dict, seslector_class.CONFIG_SCHEMA(config[selector_type])) + return { + selector_type: cast(Dict, selector_class.CONFIG_SCHEMA(config[selector_type])) + } class Selector: diff --git a/tests/helpers/test_selector.py b/tests/helpers/test_selector.py index 2b6b5cbc9f8..51490567d8e 100644 --- a/tests/helpers/test_selector.py +++ b/tests/helpers/test_selector.py @@ -14,6 +14,12 @@ def test_invalid_base_schema(schema): selector.validate_selector(schema) +def test_validate_selector(): + """Test return is the same as input.""" + schema = {"device": {"manufacturer": "mock-manuf", "model": "mock-model"}} + assert schema == selector.validate_selector(schema) + + @pytest.mark.parametrize( "schema", ( @@ -40,5 +46,5 @@ def test_device_selector_schema(schema): ), ) def test_entity_selector_schema(schema): - """Test device selector.""" + """Test entity selector.""" selector.validate_selector({"entity": schema})