Fix selector to return the selector type (#43395)
parent
edd25ae338
commit
5dcbb634f6
|
@ -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:
|
||||||
|
|
|
@ -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})
|
||||||
|
|
Loading…
Reference in New Issue