Add hide attribute support to attribute selector (#77072)

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
Franck Nijhof 2022-08-22 12:55:30 +02:00 committed by GitHub
parent 5cb91d7cef
commit 5a0e4fa5ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -206,10 +206,11 @@ class AreaSelector(Selector):
return [vol.Schema(str)(val) for val in data]
class AttributeSelectorConfig(TypedDict):
class AttributeSelectorConfig(TypedDict, total=False):
"""Class to represent an attribute selector config."""
entity_id: str
hide_attributes: list[str]
@SELECTORS.register("attribute")
@ -218,7 +219,14 @@ class AttributeSelector(Selector):
selector_type = "attribute"
CONFIG_SCHEMA = vol.Schema({vol.Required("entity_id"): cv.entity_id})
CONFIG_SCHEMA = vol.Schema(
{
vol.Required("entity_id"): cv.entity_id,
# hide_attributes is used to hide attributes in the frontend.
# A hidden attribute can still be provided manually.
vol.Optional("hide_attributes"): [str],
}
)
def __init__(self, config: AttributeSelectorConfig) -> None:
"""Instantiate a selector."""

View file

@ -458,6 +458,11 @@ def test_select_selector_schema_error(schema):
("friendly_name", "device_class"),
(None,),
),
(
{"entity_id": "sensor.abc", "hide_attributes": ["friendly_name"]},
("device_class", "state_class"),
(None,),
),
),
)
def test_attribute_selector_schema(schema, valid_selections, invalid_selections):