Section support for data entry flows (#118369)

* Add expandable support for data entry form flows

* Update config_validation.py

* optional options

* Adjust

* Correct translations of data within sections

* Update homeassistant/components/kitchen_sink/config_flow.py

Co-authored-by: Robert Resch <robert@resch.dev>

* Add missing import

* Update tests/components/kitchen_sink/test_config_flow.py

Co-authored-by: Robert Resch <robert@resch.dev>

* Format code

* Match frontend when serializing

* Move section class to data_entry_flow

* Correct serializing

* Fix import in kitchen_sink

* Move and update test

---------

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
Erik Montnemery 2024-06-25 11:02:00 +02:00 committed by GitHub
parent 3d1ff72a88
commit 0545ed8082
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 222 additions and 1 deletions

View file

@ -1037,6 +1037,7 @@ def key_dependency(
def custom_serializer(schema: Any) -> Any:
"""Serialize additional types for voluptuous_serialize."""
from .. import data_entry_flow # pylint: disable=import-outside-toplevel
from . import selector # pylint: disable=import-outside-toplevel
if schema is positive_time_period_dict:
@ -1048,6 +1049,15 @@ def custom_serializer(schema: Any) -> Any:
if schema is boolean:
return {"type": "boolean"}
if isinstance(schema, data_entry_flow.section):
return {
"type": "expandable",
"schema": voluptuous_serialize.convert(
schema.schema, custom_serializer=custom_serializer
),
"expanded": not schema.options["collapsed"],
}
if isinstance(schema, multi_select):
return {"type": "multi_select", "options": schema.options}