mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Add state selector (#77024)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
d8392ef6ba
commit
2d197fd59e
@ -741,6 +741,30 @@ class TargetSelectorConfig(TypedDict, total=False):
|
||||
device: SingleDeviceSelectorConfig
|
||||
|
||||
|
||||
class StateSelectorConfig(TypedDict):
|
||||
"""Class to represent an state selector config."""
|
||||
|
||||
entity_id: str
|
||||
|
||||
|
||||
@SELECTORS.register("state")
|
||||
class StateSelector(Selector):
|
||||
"""Selector for an entity state."""
|
||||
|
||||
selector_type = "state"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({vol.Required("entity_id"): cv.entity_id})
|
||||
|
||||
def __init__(self, config: StateSelectorConfig) -> None:
|
||||
"""Instantiate a selector."""
|
||||
super().__init__(config)
|
||||
|
||||
def __call__(self, data: Any) -> str:
|
||||
"""Validate the passed selection."""
|
||||
state: str = vol.Schema(str)(data)
|
||||
return state
|
||||
|
||||
|
||||
@SELECTORS.register("target")
|
||||
class TargetSelector(Selector):
|
||||
"""Selector of a target value (area ID, device ID, entity ID etc).
|
||||
|
@ -294,6 +294,21 @@ def test_time_selector_schema(schema, valid_selections, invalid_selections):
|
||||
_test_selector("time", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"schema,valid_selections,invalid_selections",
|
||||
(
|
||||
(
|
||||
{"entity_id": "sensor.abc"},
|
||||
("on", "armed"),
|
||||
(None, True, 1),
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_state_selector_schema(schema, valid_selections, invalid_selections):
|
||||
"""Test state selector."""
|
||||
_test_selector("state", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"schema,valid_selections,invalid_selections",
|
||||
(
|
||||
|
Loading…
x
Reference in New Issue
Block a user