mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Add multiple option to text selector (#104635)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
dfed10420c
commit
38eda9f46e
@ -1206,6 +1206,7 @@ class TextSelectorConfig(TypedDict, total=False):
|
|||||||
suffix: str
|
suffix: str
|
||||||
type: TextSelectorType
|
type: TextSelectorType
|
||||||
autocomplete: str
|
autocomplete: str
|
||||||
|
multiple: bool
|
||||||
|
|
||||||
|
|
||||||
class TextSelectorType(StrEnum):
|
class TextSelectorType(StrEnum):
|
||||||
@ -1243,6 +1244,7 @@ class TextSelector(Selector[TextSelectorConfig]):
|
|||||||
vol.Coerce(TextSelectorType), lambda val: val.value
|
vol.Coerce(TextSelectorType), lambda val: val.value
|
||||||
),
|
),
|
||||||
vol.Optional("autocomplete"): str,
|
vol.Optional("autocomplete"): str,
|
||||||
|
vol.Optional("multiple", default=False): bool,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1250,10 +1252,14 @@ class TextSelector(Selector[TextSelectorConfig]):
|
|||||||
"""Instantiate a selector."""
|
"""Instantiate a selector."""
|
||||||
super().__init__(config)
|
super().__init__(config)
|
||||||
|
|
||||||
def __call__(self, data: Any) -> str:
|
def __call__(self, data: Any) -> str | list[str]:
|
||||||
"""Validate the passed selection."""
|
"""Validate the passed selection."""
|
||||||
text: str = vol.Schema(str)(data)
|
if not self.config["multiple"]:
|
||||||
return text
|
text: str = vol.Schema(str)(data)
|
||||||
|
return text
|
||||||
|
if not isinstance(data, list):
|
||||||
|
raise vol.Invalid("Value should be a list")
|
||||||
|
return [vol.Schema(str)(val) for val in data]
|
||||||
|
|
||||||
|
|
||||||
class ThemeSelectorConfig(TypedDict):
|
class ThemeSelectorConfig(TypedDict):
|
||||||
|
@ -832,6 +832,7 @@ def test_selector_in_serializer() -> None:
|
|||||||
"selector": {
|
"selector": {
|
||||||
"text": {
|
"text": {
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
|
"multiple": False,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -602,6 +602,11 @@ def test_object_selector_schema(schema, valid_selections, invalid_selections) ->
|
|||||||
({"multiline": True}, (), ()),
|
({"multiline": True}, (), ()),
|
||||||
({"multiline": False, "type": "email"}, (), ()),
|
({"multiline": False, "type": "email"}, (), ()),
|
||||||
({"prefix": "before", "suffix": "after"}, (), ()),
|
({"prefix": "before", "suffix": "after"}, (), ()),
|
||||||
|
(
|
||||||
|
{"multiple": True},
|
||||||
|
(["abc123", "def456"],),
|
||||||
|
("abc123", None, ["abc123", None]),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_text_selector_schema(schema, valid_selections, invalid_selections) -> None:
|
def test_text_selector_schema(schema, valid_selections, invalid_selections) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user