diff --git a/homeassistant/components/template/config_flow.py b/homeassistant/components/template/config_flow.py index 36c27aa19f95..aa9c6a8f2c08 100644 --- a/homeassistant/components/template/config_flow.py +++ b/homeassistant/components/template/config_flow.py @@ -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", diff --git a/homeassistant/components/template/strings.json b/homeassistant/components/template/strings.json index e273933de54f..2f06abe9a22a 100644 --- a/homeassistant/components/template/strings.json +++ b/homeassistant/components/template/strings.json @@ -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" }, diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 5023d291ad52..4402eadeda29 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -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 diff --git a/homeassistant/helpers/schema_config_entry_flow.py b/homeassistant/helpers/schema_config_entry_flow.py index c524d25933ac..69cfc8f84509 100644 --- a/homeassistant/helpers/schema_config_entry_flow.py +++ b/homeassistant/helpers/schema_config_entry_flow.py @@ -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, )