Skip to content

Commit b00f659

Browse files
authored
Add unit of measurement to entity selector filter (home-assistant#165914)
1 parent a63516f commit b00f659

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

homeassistant/helpers/selector.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ class BaseSelectorConfig(TypedDict, total=False):
165165
vol.Optional("supported_features"): [
166166
vol.All(cv.ensure_list, [str], _validate_supported_features)
167167
],
168+
# Unit of measurement of the entity
169+
vol.Optional(CONF_UNIT_OF_MEASUREMENT): vol.All(cv.ensure_list, [str]),
168170
}
169171
)
170172

@@ -190,6 +192,7 @@ class EntityFilterSelectorConfig(TypedDict, total=False):
190192
domain: str | list[str]
191193
device_class: str | list[str]
192194
supported_features: list[str]
195+
unit_of_measurement: str | list[str]
193196

194197

195198
DEVICE_FILTER_SELECTOR_CONFIG_SCHEMA = vol.Schema(

tests/helpers/test_selector.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,24 @@ def test_device_selector_schema_error(schema) -> None:
297297
("light.abc123", "blah.blah", FAKE_UUID),
298298
(None,),
299299
),
300+
(
301+
{
302+
"filter": [
303+
{"unit_of_measurement": "baguette"},
304+
]
305+
},
306+
("light.abc123", "blah.blah", FAKE_UUID),
307+
(None,),
308+
),
309+
(
310+
{
311+
"filter": [
312+
{"unit_of_measurement": ["currywurst", "bratwurst"]},
313+
]
314+
},
315+
("light.abc123", "blah.blah", FAKE_UUID),
316+
(None,),
317+
),
300318
],
301319
)
302320
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) ->
319337
{"filter": [{"supported_features": ["light.LightEntityFeature.blah"]}]},
320338
# supported_features should be used under the filter key
321339
{"supported_features": ["light.LightEntityFeature.EFFECT"]},
340+
# unit_of_measurement should be used under the filter key
341+
{"unit_of_measurement": ["currywurst", "bratwurst"]},
342+
# Invalid unit_of_measurement
343+
{"filter": [{"unit_of_measurement": 42}]},
322344
# reorder can only be used when multiple is true
323345
{"reorder": True},
324346
{"reorder": True, "multiple": False},

0 commit comments

Comments
 (0)