From 6986e12c4de40ffeaa4be50791d3556bc2575421 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sun, 24 Nov 2024 22:21:30 +0000 Subject: [PATCH] Only default if multiple --- homeassistant/helpers/config_validation.py | 6 ++++-- tests/test_data_entry_flow.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 2be633bc084..881d175fa30 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -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} diff --git a/tests/test_data_entry_flow.py b/tests/test_data_entry_flow.py index 33ca3f5d753..4e58d42051c 100644 --- a/tests/test_data_entry_flow.py +++ b/tests/test_data_entry_flow.py @@ -1021,7 +1021,7 @@ def test_section_in_serializer() -> None: ], "type": "expandable", "multiple": False, - "default": [], + "default": None, }