From 06ade6129c18dcd48c5c87c65f6257b59cfdf1a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Wed, 27 Jan 2021 09:20:19 +0100 Subject: [PATCH] Add selectors for text and arbitrary objects (#45112) Co-authored-by: Paulus Schoutsen --- homeassistant/helpers/selector.py | 14 ++++++++++++++ tests/helpers/test_selector.py | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index 5cc7ada1bc5..b48ffb6e964 100644 --- a/homeassistant/helpers/selector.py +++ b/homeassistant/helpers/selector.py @@ -162,3 +162,17 @@ class ActionSelector(Selector): """Selector of an action sequence (script syntax).""" CONFIG_SCHEMA = vol.Schema({}) + + +@SELECTORS.register("object") +class ObjectSelector(Selector): + """Selector for an arbitrary object.""" + + CONFIG_SCHEMA = vol.Schema({}) + + +@SELECTORS.register("text") +class StringSelector(Selector): + """Selector for a multi-line text string.""" + + CONFIG_SCHEMA = vol.Schema({vol.Optional("multiline", default=False): bool}) diff --git a/tests/helpers/test_selector.py b/tests/helpers/test_selector.py index 86ee6078e87..2916d616703 100644 --- a/tests/helpers/test_selector.py +++ b/tests/helpers/test_selector.py @@ -169,3 +169,21 @@ def test_target_selector_schema(schema): def test_action_selector_schema(schema): """Test action sequence selector.""" selector.validate_selector({"action": schema}) + + +@pytest.mark.parametrize( + "schema", + ({},), +) +def test_object_selector_schema(schema): + """Test object selector.""" + selector.validate_selector({"object": schema}) + + +@pytest.mark.parametrize( + "schema", + ({}, {"multiline": True}, {"multiline": False}), +) +def test_text_selector_schema(schema): + """Test text selector.""" + selector.validate_selector({"text": schema})