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:
@@ -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(
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user