1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add filters to climate and light service descriptions (#86162)

* Add filters to climate and light service descriptions

* Allow specifying enums directly

* Update service descriptions

* Adjust test

* Cache entity features

* Lint

* Improve error handling, add list of known base components

* Don't allow specifying an entity feature as int
This commit is contained in:
Erik Montnemery
2023-03-16 15:59:51 +01:00
committed by GitHub
parent c81a38effb
commit 9384ec18f8
7 changed files with 467 additions and 14 deletions

View File

@@ -69,10 +69,9 @@ def _test_selector(
# Serialize selector
selector_instance = selector.selector({selector_type: schema})
assert (
selector.selector(selector_instance.serialize()["selector"]).config
== selector_instance.config
)
assert selector_instance.serialize() == {
"selector": {selector_type: selector_instance.config}
}
# Test serialized selector can be dumped to YAML
yaml.dump(selector_instance.serialize())
@@ -227,6 +226,29 @@ def test_device_selector_schema(schema, valid_selections, invalid_selections) ->
("light.abc123", "binary_sensor.abc123", FAKE_UUID),
(None,),
),
(
{
"filter": [
{"supported_features": ["light.LightEntityFeature.EFFECT"]},
]
},
("light.abc123", "blah.blah", FAKE_UUID),
(None,),
),
(
{
"filter": [
{
"supported_features": [
"light.LightEntityFeature.EFFECT",
"light.LightEntityFeature.TRANSITION",
]
},
]
},
("light.abc123", "blah.blah", FAKE_UUID),
(None,),
),
),
)
def test_entity_selector_schema(schema, valid_selections, invalid_selections) -> None:
@@ -234,6 +256,25 @@ def test_entity_selector_schema(schema, valid_selections, invalid_selections) ->
_test_selector("entity", schema, valid_selections, invalid_selections)
@pytest.mark.parametrize(
"schema",
(
# Feature should be string specifying an enum member, not an int
{"filter": [{"supported_features": [1]}]},
# Invalid feature
{"filter": [{"supported_features": ["blah"]}]},
# Unknown feature enum
{"filter": [{"supported_features": ["blah.FooEntityFeature.blah"]}]},
# Unknown feature enum member
{"filter": [{"supported_features": ["light.LightEntityFeature.blah"]}]},
),
)
def test_entity_selector_schema_error(schema) -> None:
"""Test number selector."""
with pytest.raises(vol.Invalid):
selector.validate_selector({"entity": schema})
@pytest.mark.parametrize(
("schema", "valid_selections", "invalid_selections"),
(
@@ -359,7 +400,7 @@ def test_addon_selector_schema(schema, valid_selections, invalid_selections) ->
@pytest.mark.parametrize(
("schema", "valid_selections", "invalid_selections"),
(({}, (1, "one", None), ()),), # Everything can be coarced to bool
(({}, (1, "one", None), ()),), # Everything can be coerced to bool
)
def test_boolean_selector_schema(schema, valid_selections, invalid_selections) -> None:
"""Test boolean selector."""