mirror of
https://github.com/home-assistant/core.git
synced 2025-08-31 02:11:32 +02:00
Allow use of Selector in ObjectSelector fields
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Mapping, Sequence
|
||||
from copy import deepcopy
|
||||
from enum import StrEnum
|
||||
from functools import cache
|
||||
import importlib
|
||||
@@ -1159,7 +1160,7 @@ class ObjectSelectorField(TypedDict):
|
||||
|
||||
label: str
|
||||
required: bool
|
||||
selector: dict[str, Any]
|
||||
selector: Required[Selector | dict[str, Any]]
|
||||
|
||||
|
||||
class ObjectSelectorConfig(BaseSelectorConfig):
|
||||
@@ -1168,7 +1169,7 @@ class ObjectSelectorConfig(BaseSelectorConfig):
|
||||
fields: dict[str, ObjectSelectorField]
|
||||
multiple: bool
|
||||
label_field: str
|
||||
description_field: bool
|
||||
description_field: str
|
||||
translation_key: str
|
||||
|
||||
|
||||
@@ -1182,7 +1183,7 @@ class ObjectSelector(Selector[ObjectSelectorConfig]):
|
||||
{
|
||||
vol.Optional("fields"): {
|
||||
str: {
|
||||
vol.Required("selector"): dict,
|
||||
vol.Required("selector"): vol.Any(Selector, dict),
|
||||
vol.Optional("required"): bool,
|
||||
vol.Optional("label"): str,
|
||||
}
|
||||
@@ -1198,6 +1199,17 @@ class ObjectSelector(Selector[ObjectSelectorConfig]):
|
||||
"""Instantiate a selector."""
|
||||
super().__init__(config)
|
||||
|
||||
def serialize(self) -> dict[str, dict[str, ObjectSelectorConfig]]:
|
||||
"""Serialize ObjectSelector for voluptuous_serialize."""
|
||||
_config = deepcopy(self.config)
|
||||
if "fields" in _config:
|
||||
for items in _config["fields"].values():
|
||||
if isinstance(items["selector"], Selector):
|
||||
items["selector"] = {
|
||||
items["selector"].selector_type: items["selector"].config
|
||||
}
|
||||
return {"selector": {self.selector_type: _config}}
|
||||
|
||||
def __call__(self, data: Any) -> Any:
|
||||
"""Validate the passed selection."""
|
||||
return data
|
||||
|
Reference in New Issue
Block a user