Only default if multiple

This commit is contained in:
G Johansson 2024-11-24 22:21:30 +00:00
parent 073ba775b2
commit 6986e12c4d
2 changed files with 5 additions and 3 deletions

View File

@ -1136,7 +1136,7 @@ def _custom_serializer(schema: Any, *, allow_section: bool) -> Any:
if isinstance(schema, data_entry_flow.section):
if not allow_section:
raise ValueError("Nesting expandable sections is not supported")
return {
section_schema = {
"type": "expandable",
"schema": voluptuous_serialize.convert(
schema.schema,
@ -1146,8 +1146,10 @@ def _custom_serializer(schema: Any, *, allow_section: bool) -> Any:
),
"expanded": not schema.options["collapsed"],
"multiple": schema.options["multiple"],
"default": schema.options.get("default"),
}
if schema.options["multiple"]:
section_schema["default"] = schema.options["default"]
return section_schema
if isinstance(schema, multi_select):
return {"type": "multi_select", "options": schema.options}

View File

@ -1021,7 +1021,7 @@ def test_section_in_serializer() -> None:
],
"type": "expandable",
"multiple": False,
"default": [],
"default": None,
}