From 5a0e4fa5eedff0cda29f196c5a05f0fd2cf84f75 Mon Sep 17 00:00:00 2001 From: Franck Nijhof <git@frenck.dev> Date: Mon, 22 Aug 2022 12:55:30 +0200 Subject: [PATCH] Add hide attribute support to attribute selector (#77072) Co-authored-by: Erik Montnemery <erik@montnemery.com> --- homeassistant/helpers/selector.py | 12 ++++++++++-- tests/helpers/test_selector.py | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index 9655f93ace5..93abd6ca4e4 100644 --- a/homeassistant/helpers/selector.py +++ b/homeassistant/helpers/selector.py @@ -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.""" diff --git a/tests/helpers/test_selector.py b/tests/helpers/test_selector.py index 2d870a85f6f..c809eaea8bd 100644 --- a/tests/helpers/test_selector.py +++ b/tests/helpers/test_selector.py @@ -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): -- GitLab