1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 08:26:41 +01:00

Add unit of measurement to entity selector filter (#165914)

This commit is contained in:
Erik Montnemery
2026-03-18 17:01:21 +01:00
committed by GitHub
parent a63516ff71
commit b00f6593f1
2 changed files with 25 additions and 0 deletions

View File

@@ -165,6 +165,8 @@ ENTITY_FILTER_SELECTOR_CONFIG_SCHEMA = vol.Schema(
vol.Optional("supported_features"): [
vol.All(cv.ensure_list, [str], _validate_supported_features)
],
# Unit of measurement of the entity
vol.Optional(CONF_UNIT_OF_MEASUREMENT): vol.All(cv.ensure_list, [str]),
}
)
@@ -190,6 +192,7 @@ class EntityFilterSelectorConfig(TypedDict, total=False):
domain: str | list[str]
device_class: str | list[str]
supported_features: list[str]
unit_of_measurement: str | list[str]
DEVICE_FILTER_SELECTOR_CONFIG_SCHEMA = vol.Schema(

View File

@@ -297,6 +297,24 @@ def test_device_selector_schema_error(schema) -> None:
("light.abc123", "blah.blah", FAKE_UUID),
(None,),
),
(
{
"filter": [
{"unit_of_measurement": "baguette"},
]
},
("light.abc123", "blah.blah", FAKE_UUID),
(None,),
),
(
{
"filter": [
{"unit_of_measurement": ["currywurst", "bratwurst"]},
]
},
("light.abc123", "blah.blah", FAKE_UUID),
(None,),
),
],
)
def test_entity_selector_schema(schema, valid_selections, invalid_selections) -> None:
@@ -319,6 +337,10 @@ def test_entity_selector_schema(schema, valid_selections, invalid_selections) ->
{"filter": [{"supported_features": ["light.LightEntityFeature.blah"]}]},
# supported_features should be used under the filter key
{"supported_features": ["light.LightEntityFeature.EFFECT"]},
# unit_of_measurement should be used under the filter key
{"unit_of_measurement": ["currywurst", "bratwurst"]},
# Invalid unit_of_measurement
{"filter": [{"unit_of_measurement": 42}]},
# reorder can only be used when multiple is true
{"reorder": True},
{"reorder": True, "multiple": False},