Add hide attribute support to attribute selector (#77072)
Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
5cb91d7cef
commit
5a0e4fa5ee
2 changed files with 15 additions and 2 deletions
|
@ -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."""
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue