mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Add attribute support to state selector (#77071)
This commit is contained in:
parent
18246bb8c8
commit
453307e01a
@ -741,10 +741,11 @@ class TargetSelectorConfig(TypedDict, total=False):
|
|||||||
device: SingleDeviceSelectorConfig
|
device: SingleDeviceSelectorConfig
|
||||||
|
|
||||||
|
|
||||||
class StateSelectorConfig(TypedDict):
|
class StateSelectorConfig(TypedDict, total=False):
|
||||||
"""Class to represent an state selector config."""
|
"""Class to represent an state selector config."""
|
||||||
|
|
||||||
entity_id: str
|
entity_id: str
|
||||||
|
attribute: str
|
||||||
|
|
||||||
|
|
||||||
@SELECTORS.register("state")
|
@SELECTORS.register("state")
|
||||||
@ -753,7 +754,12 @@ class StateSelector(Selector):
|
|||||||
|
|
||||||
selector_type = "state"
|
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:
|
def __init__(self, config: StateSelectorConfig) -> None:
|
||||||
"""Instantiate a selector."""
|
"""Instantiate a selector."""
|
||||||
|
@ -302,6 +302,11 @@ def test_time_selector_schema(schema, valid_selections, invalid_selections):
|
|||||||
("on", "armed"),
|
("on", "armed"),
|
||||||
(None, True, 1),
|
(None, True, 1),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
{"entity_id": "sensor.abc", "attribute": "device_class"},
|
||||||
|
("temperature", "humidity"),
|
||||||
|
(None,),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_state_selector_schema(schema, valid_selections, invalid_selections):
|
def test_state_selector_schema(schema, valid_selections, invalid_selections):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user