mirror of
https://github.com/home-assistant/core.git
synced 2026-04-20 16:39:02 +02:00
Sort template config menu step by user language (#151596)
This commit is contained in:
@@ -514,7 +514,7 @@ TEMPLATE_TYPES = [
|
||||
]
|
||||
|
||||
CONFIG_FLOW = {
|
||||
"user": SchemaFlowMenuStep(TEMPLATE_TYPES),
|
||||
"user": SchemaFlowMenuStep(TEMPLATE_TYPES, True),
|
||||
Platform.ALARM_CONTROL_PANEL: SchemaFlowFormStep(
|
||||
config_schema(Platform.ALARM_CONTROL_PANEL),
|
||||
preview="template",
|
||||
|
||||
@@ -378,23 +378,23 @@
|
||||
"title": "Template sensor"
|
||||
},
|
||||
"user": {
|
||||
"description": "This helper allows you to create helper entities that define their state using a template.",
|
||||
"description": "This helper allows you to create helper entities that define their state using a template. What kind of template would you like to create?",
|
||||
"menu_options": {
|
||||
"alarm_control_panel": "Template an alarm control panel",
|
||||
"binary_sensor": "Template a binary sensor",
|
||||
"button": "Template a button",
|
||||
"cover": "Template a cover",
|
||||
"event": "Template an event",
|
||||
"fan": "Template a fan",
|
||||
"image": "Template an image",
|
||||
"light": "Template a light",
|
||||
"lock": "Template a lock",
|
||||
"number": "Template a number",
|
||||
"select": "Template a select",
|
||||
"sensor": "Template a sensor",
|
||||
"switch": "Template a switch",
|
||||
"update": "Template an update",
|
||||
"vacuum": "Template a vacuum"
|
||||
"alarm_control_panel": "[%key:component::alarm_control_panel::title%]",
|
||||
"binary_sensor": "[%key:component::binary_sensor::title%]",
|
||||
"button": "[%key:component::button::title%]",
|
||||
"cover": "[%key:component::cover::title%]",
|
||||
"event": "[%key:component::event::title%]",
|
||||
"fan": "[%key:component::fan::title%]",
|
||||
"image": "[%key:component::image::title%]",
|
||||
"light": "[%key:component::light::title%]",
|
||||
"lock": "[%key:component::lock::title%]",
|
||||
"number": "[%key:component::number::title%]",
|
||||
"select": "[%key:component::select::title%]",
|
||||
"sensor": "[%key:component::sensor::title%]",
|
||||
"switch": "[%key:component::switch::title%]",
|
||||
"update": "[%key:component::update::title%]",
|
||||
"vacuum": "[%key:component::vacuum::title%]"
|
||||
},
|
||||
"title": "Template helper"
|
||||
},
|
||||
|
||||
@@ -142,6 +142,7 @@ class FlowResult(TypedDict, Generic[_FlowContextT, _HandlerT], total=False):
|
||||
progress_task: asyncio.Task[Any] | None
|
||||
reason: str
|
||||
required: bool
|
||||
sort: bool
|
||||
step_id: str
|
||||
title: str
|
||||
translation_domain: str
|
||||
@@ -854,6 +855,7 @@ class FlowHandler(Generic[_FlowContextT, _FlowResultT, _HandlerT]):
|
||||
*,
|
||||
step_id: str | None = None,
|
||||
menu_options: Container[str],
|
||||
sort: bool = False,
|
||||
description_placeholders: Mapping[str, str] | None = None,
|
||||
) -> _FlowResultT:
|
||||
"""Show a navigation menu to the user.
|
||||
@@ -868,6 +870,8 @@ class FlowHandler(Generic[_FlowContextT, _FlowResultT, _HandlerT]):
|
||||
menu_options=menu_options,
|
||||
description_placeholders=description_placeholders,
|
||||
)
|
||||
if sort:
|
||||
flow_result["sort"] = sort
|
||||
if step_id is not None:
|
||||
flow_result["step_id"] = step_id
|
||||
return flow_result
|
||||
|
||||
@@ -118,6 +118,10 @@ class SchemaFlowMenuStep(SchemaFlowStep):
|
||||
`SchemaCommonFlowHandler`.
|
||||
"""
|
||||
|
||||
sort: bool = False
|
||||
"""If true, menu options will be alphabetically sorted by the option label.
|
||||
"""
|
||||
|
||||
|
||||
class SchemaCommonFlowHandler:
|
||||
"""Handle a schema based config or options flow."""
|
||||
@@ -270,6 +274,7 @@ class SchemaCommonFlowHandler:
|
||||
return self._handler.async_show_menu(
|
||||
step_id=next_step_id,
|
||||
menu_options=await self._get_options(menu_step),
|
||||
sort=menu_step.sort,
|
||||
)
|
||||
|
||||
form_step = cast(SchemaFlowFormStep, self._flow[next_step_id])
|
||||
@@ -323,6 +328,7 @@ class SchemaCommonFlowHandler:
|
||||
return self._handler.async_show_menu(
|
||||
step_id=step_id,
|
||||
menu_options=await self._get_options(menu_step),
|
||||
sort=menu_step.sort,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user