Add filters to cover/services.yaml (#95854)

This commit is contained in:
Erik Montnemery 2023-07-08 11:51:02 +02:00 committed by GitHub
parent b5678a12ec
commit 3d064b7d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 5 deletions

View File

@ -6,6 +6,8 @@ open_cover:
target:
entity:
domain: cover
supported_features:
- cover.CoverEntityFeature.OPEN
close_cover:
name: Close
@ -13,6 +15,8 @@ close_cover:
target:
entity:
domain: cover
supported_features:
- cover.CoverEntityFeature.CLOSE
toggle:
name: Toggle
@ -20,6 +24,9 @@ toggle:
target:
entity:
domain: cover
supported_features:
- - cover.CoverEntityFeature.CLOSE
- cover.CoverEntityFeature.OPEN
set_cover_position:
name: Set position
@ -27,6 +34,8 @@ set_cover_position:
target:
entity:
domain: cover
supported_features:
- cover.CoverEntityFeature.SET_POSITION
fields:
position:
name: Position
@ -44,6 +53,8 @@ stop_cover:
target:
entity:
domain: cover
supported_features:
- cover.CoverEntityFeature.STOP
open_cover_tilt:
name: Open tilt
@ -51,6 +62,8 @@ open_cover_tilt:
target:
entity:
domain: cover
supported_features:
- cover.CoverEntityFeature.OPEN_TILT
close_cover_tilt:
name: Close tilt
@ -58,6 +71,8 @@ close_cover_tilt:
target:
entity:
domain: cover
supported_features:
- cover.CoverEntityFeature.CLOSE_TILT
toggle_cover_tilt:
name: Toggle tilt
@ -65,6 +80,9 @@ toggle_cover_tilt:
target:
entity:
domain: cover
supported_features:
- - cover.CoverEntityFeature.CLOSE_TILT
- cover.CoverEntityFeature.OPEN_TILT
set_cover_tilt_position:
name: Set tilt position
@ -72,6 +90,8 @@ set_cover_tilt_position:
target:
entity:
domain: cover
supported_features:
- cover.CoverEntityFeature.SET_TILT_POSITION
fields:
tilt_position:
name: Tilt position
@ -89,3 +109,5 @@ stop_cover_tilt:
target:
entity:
domain: cover
supported_features:
- cover.CoverEntityFeature.STOP_TILT

View File

@ -122,12 +122,9 @@ def _entity_features() -> dict[str, type[IntFlag]]:
}
def _validate_supported_feature(supported_feature: int | str) -> int:
def _validate_supported_feature(supported_feature: str) -> int:
"""Validate a supported feature and resolve an enum string to its value."""
if isinstance(supported_feature, int):
return supported_feature
known_entity_features = _entity_features()
try:
@ -144,6 +141,20 @@ def _validate_supported_feature(supported_feature: int | str) -> int:
raise vol.Invalid(f"Unknown supported feature '{supported_feature}'") from exc
def _validate_supported_features(supported_features: int | list[str]) -> int:
"""Validate a supported feature and resolve an enum string to its value."""
if isinstance(supported_features, int):
return supported_features
feature_mask = 0
for supported_feature in supported_features:
feature_mask |= _validate_supported_feature(supported_feature)
return feature_mask
ENTITY_FILTER_SELECTOR_CONFIG_SCHEMA = vol.Schema(
{
# Integration that provided the entity
@ -153,7 +164,9 @@ ENTITY_FILTER_SELECTOR_CONFIG_SCHEMA = vol.Schema(
# Device class of the entity
vol.Optional("device_class"): vol.All(cv.ensure_list, [str]),
# Features supported by the entity
vol.Optional("supported_features"): [vol.All(str, _validate_supported_feature)],
vol.Optional("supported_features"): [
vol.All(cv.ensure_list, [str], _validate_supported_features)
],
}
)

View File

@ -235,6 +235,22 @@ def test_device_selector_schema(schema, valid_selections, invalid_selections) ->
("light.abc123", "blah.blah", FAKE_UUID),
(None,),
),
(
{
"filter": [
{
"supported_features": [
[
"light.LightEntityFeature.EFFECT",
"light.LightEntityFeature.TRANSITION",
]
]
},
]
},
("light.abc123", "blah.blah", FAKE_UUID),
(None,),
),
(
{
"filter": [