From 95b8a99304435c4a809a4f8866dac3c3df78296f Mon Sep 17 00:00:00 2001 From: thekiwismarthome <134335563+thekiwismarthome@users.noreply.github.com> Date: Fri, 13 Feb 2026 14:53:47 +1300 Subject: [PATCH] Update config_flow.py --- .../shopping_list_manager/config_flow.py | 73 ++++++++++++++++++- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/custom_components/shopping_list_manager/config_flow.py b/custom_components/shopping_list_manager/config_flow.py index 8492172..2cf7bc7 100644 --- a/custom_components/shopping_list_manager/config_flow.py +++ b/custom_components/shopping_list_manager/config_flow.py @@ -1,5 +1,7 @@ """Config flow for Shopping List Manager.""" +import voluptuous as vol from homeassistant import config_entries +from homeassistant.core import callback from .const import DOMAIN @@ -9,6 +11,10 @@ class ShoppingListManagerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): VERSION = 1 + def __init__(self): + """Initialize config flow.""" + self._data = {} + async def async_step_user(self, user_input=None): """Handle the initial step.""" # Only allow one instance @@ -16,10 +22,71 @@ class ShoppingListManagerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): return self.async_abort(reason="single_instance_allowed") if user_input is not None: + # Store initial list name + self._data["initial_list_name"] = user_input.get("list_name", "Shopping List") + return await self.async_step_features() + + # Show setup form + return self.async_show_form( + step_id="user", + data_schema=vol.Schema({ + vol.Optional("list_name", default="Shopping List"): str, + }), + description_placeholders={ + "version": "2.0.0", + } + ) + + async def async_step_features(self, user_input=None): + """Configure optional features.""" + if user_input is not None: + self._data.update(user_input) return self.async_create_entry( title="Shopping List Manager", - data={} + data=self._data ) - # Show simple form - return self.async_show_form(step_id="user") \ No newline at end of file + return self.async_show_form( + step_id="features", + data_schema=vol.Schema({ + vol.Optional("enable_price_tracking", default=True): bool, + vol.Optional("enable_image_search", default=True): bool, + vol.Optional("metric_units_only", default=True): bool, + }), + description_placeholders={ + "features": "Configure optional features for your shopping lists" + } + ) + + @staticmethod + @callback + def async_get_options_flow(config_entry): + """Get the options flow for this handler.""" + return OptionsFlowHandler(config_entry) + + +class OptionsFlowHandler(config_entries.OptionsFlow): + """Handle options flow for Shopping List Manager.""" + + def __init__(self, config_entry): + """Initialize options flow.""" + self.config_entry = config_entry + + async def async_step_init(self, user_input=None): + """Manage the options.""" + if user_input is not None: + return self.async_create_entry(title="", data=user_input) + + return self.async_show_form( + step_id="init", + data_schema=vol.Schema({ + vol.Optional( + "enable_price_tracking", + default=self.config_entry.data.get("enable_price_tracking", True) + ): bool, + vol.Optional( + "enable_image_search", + default=self.config_entry.data.get("enable_image_search", True) + ): bool, + }) + )