diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index 9655f93ace55fbb5e493bc67ffcd9fec5f3a840c..93abd6ca4e4b7f11ddce100eb79cdcc3c41b539a 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 2d870a85f6f52ebac2ec9a25c4cdd2ac5f6dde64..c809eaea8bd94ce5a43540ce91c23a0a4a1a1612 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):