From b4ea6bc7f03df986d6be378c07547b56910e7f79 Mon Sep 17 00:00:00 2001 From: thekiwismarthome <134335563+thekiwismarthome@users.noreply.github.com> Date: Fri, 13 Feb 2026 21:36:37 +1300 Subject: [PATCH] Update config_flow.py --- .../shopping_list_manager/config_flow.py | 75 +++++++------------ 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/custom_components/shopping_list_manager/config_flow.py b/custom_components/shopping_list_manager/config_flow.py index f4ad7ce..4ce713d 100644 --- a/custom_components/shopping_list_manager/config_flow.py +++ b/custom_components/shopping_list_manager/config_flow.py @@ -11,10 +11,6 @@ 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 @@ -22,47 +18,23 @@ class ShoppingListManagerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): return self.async_abort(reason="single_instance_allowed") if user_input is not None: - # Store country and initial list name - self._data["country"] = user_input.get("country", "NZ") - self._data["initial_list_name"] = user_input.get("list_name", "Shopping List") - return await self.async_step_features() - - # Show setup form with country selection - return self.async_show_form( - step_id="user", - data_schema=vol.Schema({ - vol.Required("country", default="NZ"): vol.In({ - "NZ": "New Zealand", - "AU": "Australia", - "US": "United States", - "GB": "United Kingdom", - "CA": "Canada", - }), - 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) + # Create entry with default country return self.async_create_entry( title="Shopping List Manager", - data=self._data + data={"country": "NZ"}, # Default to NZ + options={ + "country": "NZ", + "enable_price_tracking": True, + "enable_image_search": True, + "metric_units_only": True, + } ) + # Show simple setup form (no country selection here) 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, - }), + step_id="user", description_placeholders={ - "features": "Configure optional features for your shopping lists" + "info": "Country and other settings can be configured after setup via the Configure button." } ) @@ -83,15 +55,19 @@ class OptionsFlowHandler(config_entries.OptionsFlow): async def async_step_init(self, user_input=None): """Manage the options.""" if user_input is not None: + # Update options return self.async_create_entry(title="", data=user_input) + # Get current settings + current_country = self.config_entry.options.get( + "country", + self.config_entry.data.get("country", "NZ") + ) + return self.async_show_form( step_id="init", data_schema=vol.Schema({ - vol.Required( - "country", - default=self.config_entry.data.get("country", "NZ") - ): vol.In({ + vol.Required("country", default=current_country): vol.In({ "NZ": "New Zealand", "AU": "Australia", "US": "United States", @@ -100,11 +76,18 @@ class OptionsFlowHandler(config_entries.OptionsFlow): }), vol.Optional( "enable_price_tracking", - default=self.config_entry.data.get("enable_price_tracking", True) + default=self.config_entry.options.get("enable_price_tracking", True) ): bool, vol.Optional( "enable_image_search", - default=self.config_entry.data.get("enable_image_search", True) + default=self.config_entry.options.get("enable_image_search", True) ): bool, - }) + vol.Optional( + "metric_units_only", + default=self.config_entry.options.get("metric_units_only", True) + ): bool, + }), + description_placeholders={ + "info": "Changing country will reload the product catalog on next restart." + } )