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:
parent
3d1ff72a88
commit
0545ed8082
9 changed files with 222 additions and 1 deletions
|
@ -906,6 +906,33 @@ class FlowHandler(Generic[_FlowResultT, _HandlerT]):
|
|||
self.__progress_task = progress_task
|
||||
|
||||
|
||||
class SectionConfig(TypedDict, total=False):
|
||||
"""Class to represent a section config."""
|
||||
|
||||
collapsed: bool
|
||||
|
||||
|
||||
class section:
|
||||
"""Data entry flow section."""
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional("collapsed", default=False): bool,
|
||||
},
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self, schema: vol.Schema, options: SectionConfig | None = None
|
||||
) -> None:
|
||||
"""Initialize."""
|
||||
self.schema = schema
|
||||
self.options: SectionConfig = self.CONFIG_SCHEMA(options or {})
|
||||
|
||||
def __call__(self, value: Any) -> Any:
|
||||
"""Validate input."""
|
||||
return self.schema(value)
|
||||
|
||||
|
||||
# These can be removed if no deprecated constant are in this module anymore
|
||||
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
|
||||
__dir__ = partial(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue