Add attribute support to state selector (#77071)

pull/77078/head
Franck Nijhof 2022-08-20 19:30:38 +02:00 committed by GitHub
parent 18246bb8c8
commit 453307e01a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -741,10 +741,11 @@ class TargetSelectorConfig(TypedDict, total=False):
device: SingleDeviceSelectorConfig
class StateSelectorConfig(TypedDict):
class StateSelectorConfig(TypedDict, total=False):
"""Class to represent an state selector config."""
entity_id: str
attribute: str
@SELECTORS.register("state")
@ -753,7 +754,12 @@ class StateSelector(Selector):
selector_type = "state"
CONFIG_SCHEMA = vol.Schema({vol.Required("entity_id"): cv.entity_id})
CONFIG_SCHEMA = vol.Schema(
{
vol.Required("entity_id"): cv.entity_id,
vol.Optional("attribute"): str,
}
)
def __init__(self, config: StateSelectorConfig) -> None:
"""Instantiate a selector."""

View File

@ -302,6 +302,11 @@ def test_time_selector_schema(schema, valid_selections, invalid_selections):
("on", "armed"),
(None, True, 1),
),
(
{"entity_id": "sensor.abc", "attribute": "device_class"},
("temperature", "humidity"),
(None,),
),
),
)
def test_state_selector_schema(schema, valid_selections, invalid_selections):