Fix selector to return the selector type (#43395)

pull/43403/head
Bram Kragten 2020-11-19 16:48:43 +01:00 committed by GitHub
parent edd25ae338
commit 5dcbb634f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -18,12 +18,14 @@ def validate_selector(config: Any) -> Dict:
selector_type = list(config)[0] 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") 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: class Selector:

View File

@ -14,6 +14,12 @@ def test_invalid_base_schema(schema):
selector.validate_selector(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( @pytest.mark.parametrize(
"schema", "schema",
( (
@ -40,5 +46,5 @@ def test_device_selector_schema(schema):
), ),
) )
def test_entity_selector_schema(schema): def test_entity_selector_schema(schema):
"""Test device selector.""" """Test entity selector."""
selector.validate_selector({"entity": schema}) selector.validate_selector({"entity": schema})