mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Allow multiple sections
This commit is contained in:
parent
84630ef8cc
commit
ff51d924b4
@ -89,7 +89,29 @@ class OptionsFlowHandler(OptionsFlow):
|
||||
): int,
|
||||
}
|
||||
),
|
||||
{"collapsed": False},
|
||||
{
|
||||
"collapsed": False,
|
||||
"multiple": True,
|
||||
},
|
||||
),
|
||||
vol.Required("section_2"): data_entry_flow.section(
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Optional(
|
||||
"a",
|
||||
default=2,
|
||||
): int,
|
||||
vol.Optional(
|
||||
"b",
|
||||
default=4,
|
||||
): int,
|
||||
}
|
||||
),
|
||||
{
|
||||
"collapsed": False,
|
||||
"multiple": True,
|
||||
"default": [{"a": 7, "b": 10}],
|
||||
},
|
||||
),
|
||||
}
|
||||
),
|
||||
|
@ -23,6 +23,14 @@
|
||||
},
|
||||
"description": "This section allows input of some extra data",
|
||||
"name": "Collapsible section"
|
||||
},
|
||||
"section_2": {
|
||||
"data": {
|
||||
"a": "A",
|
||||
"b": "B"
|
||||
},
|
||||
"description": "Some datapoints",
|
||||
"name": "Data point"
|
||||
}
|
||||
},
|
||||
"submit": "Save!"
|
||||
|
@ -908,6 +908,8 @@ class SectionConfig(TypedDict, total=False):
|
||||
"""Class to represent a section config."""
|
||||
|
||||
collapsed: bool
|
||||
multiple: bool
|
||||
default: list[Any]
|
||||
|
||||
|
||||
class section:
|
||||
@ -916,6 +918,8 @@ class section:
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional("collapsed", default=False): bool,
|
||||
vol.Optional("multiple", default=False): bool,
|
||||
vol.Optional("default", default=[]): list[Any],
|
||||
},
|
||||
)
|
||||
|
||||
@ -928,7 +932,11 @@ class section:
|
||||
|
||||
def __call__(self, value: Any) -> Any:
|
||||
"""Validate input."""
|
||||
return self.schema(value)
|
||||
if not self.options["multiple"]:
|
||||
return self.schema(value)
|
||||
if not isinstance(value, list):
|
||||
raise vol.Invalid("Value should be a list")
|
||||
return [vol.Schema(dict)(val) for val in value]
|
||||
|
||||
|
||||
# These can be removed if no deprecated constant are in this module anymore
|
||||
|
@ -1145,6 +1145,8 @@ def _custom_serializer(schema: Any, *, allow_section: bool) -> Any:
|
||||
),
|
||||
),
|
||||
"expanded": not schema.options["collapsed"],
|
||||
"multiple": schema.options["multiple"],
|
||||
"default": schema.options["default"],
|
||||
}
|
||||
|
||||
if isinstance(schema, multi_select):
|
||||
|
Loading…
x
Reference in New Issue
Block a user