Skip to content
Snippets Groups Projects
Unverified Commit 5a0e4fa5 authored by Franck Nijhof's avatar Franck Nijhof Committed by GitHub
Browse files

Add hide attribute support to attribute selector (#77072)

parent 5cb91d7c
No related branches found
No related tags found
No related merge requests found
...@@ -206,10 +206,11 @@ class AreaSelector(Selector): ...@@ -206,10 +206,11 @@ class AreaSelector(Selector):
return [vol.Schema(str)(val) for val in data] return [vol.Schema(str)(val) for val in data]
class AttributeSelectorConfig(TypedDict): class AttributeSelectorConfig(TypedDict, total=False):
"""Class to represent an attribute selector config.""" """Class to represent an attribute selector config."""
entity_id: str entity_id: str
hide_attributes: list[str]
@SELECTORS.register("attribute") @SELECTORS.register("attribute")
...@@ -218,7 +219,14 @@ class AttributeSelector(Selector): ...@@ -218,7 +219,14 @@ class AttributeSelector(Selector):
selector_type = "attribute" 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: def __init__(self, config: AttributeSelectorConfig) -> None:
"""Instantiate a selector.""" """Instantiate a selector."""
......
...@@ -458,6 +458,11 @@ def test_select_selector_schema_error(schema): ...@@ -458,6 +458,11 @@ def test_select_selector_schema_error(schema):
("friendly_name", "device_class"), ("friendly_name", "device_class"),
(None,), (None,),
), ),
(
{"entity_id": "sensor.abc", "hide_attributes": ["friendly_name"]},
("device_class", "state_class"),
(None,),
),
), ),
) )
def test_attribute_selector_schema(schema, valid_selections, invalid_selections): def test_attribute_selector_schema(schema, valid_selections, invalid_selections):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment