diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index b699910cf69..03214ab6f5b 100644 --- a/homeassistant/helpers/selector.py +++ b/homeassistant/helpers/selector.py @@ -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( diff --git a/tests/helpers/test_selector.py b/tests/helpers/test_selector.py index 34a87c0ca40..0d9eb6963f8 100644 --- a/tests/helpers/test_selector.py +++ b/tests/helpers/test_selector.py @@ -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},