diff --git a/homeassistant/components/kitchen_sink/config_flow.py b/homeassistant/components/kitchen_sink/config_flow.py index 019d1dddcad535..aadef335202655 100644 --- a/homeassistant/components/kitchen_sink/config_flow.py +++ b/homeassistant/components/kitchen_sink/config_flow.py @@ -89,7 +89,29 @@ async def async_step_options_1( ): 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}], + }, ), } ), diff --git a/homeassistant/components/kitchen_sink/strings.json b/homeassistant/components/kitchen_sink/strings.json index 63e27e046376eb..f09d88e62eab8b 100644 --- a/homeassistant/components/kitchen_sink/strings.json +++ b/homeassistant/components/kitchen_sink/strings.json @@ -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!" diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 338b5f3992f4b6..b6aa744de0f6dd 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -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 @@ def __init__( 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 diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 2b35ebade761b7..365024a537e10e 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -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):