Update config_flow.py

This commit is contained in:
thekiwismarthome
2026-02-13 21:36:37 +13:00
committed by GitHub
parent e09f9004a6
commit b4ea6bc7f0
@@ -11,10 +11,6 @@ class ShoppingListManagerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
def __init__(self):
"""Initialize config flow."""
self._data = {}
async def async_step_user(self, user_input=None): async def async_step_user(self, user_input=None):
"""Handle the initial step.""" """Handle the initial step."""
# Only allow one instance # Only allow one instance
@@ -22,47 +18,23 @@ class ShoppingListManagerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_abort(reason="single_instance_allowed") return self.async_abort(reason="single_instance_allowed")
if user_input is not None: if user_input is not None:
# Store country and initial list name # Create entry with default country
self._data["country"] = user_input.get("country", "NZ") return self.async_create_entry(
self._data["initial_list_name"] = user_input.get("list_name", "Shopping List") title="Shopping List Manager",
return await self.async_step_features() data={"country": "NZ"}, # Default to NZ
options={
# Show setup form with country selection "country": "NZ",
return self.async_show_form( "enable_price_tracking": True,
step_id="user", "enable_image_search": True,
data_schema=vol.Schema({ "metric_units_only": True,
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): # Show simple setup form (no country selection here)
"""Configure optional features."""
if user_input is not None:
self._data.update(user_input)
return self.async_create_entry(
title="Shopping List Manager",
data=self._data
)
return self.async_show_form( return self.async_show_form(
step_id="features", step_id="user",
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={ 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): async def async_step_init(self, user_input=None):
"""Manage the options.""" """Manage the options."""
if user_input is not None: if user_input is not None:
# Update options
return self.async_create_entry(title="", data=user_input) 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( return self.async_show_form(
step_id="init", step_id="init",
data_schema=vol.Schema({ data_schema=vol.Schema({
vol.Required( vol.Required("country", default=current_country): vol.In({
"country",
default=self.config_entry.data.get("country", "NZ")
): vol.In({
"NZ": "New Zealand", "NZ": "New Zealand",
"AU": "Australia", "AU": "Australia",
"US": "United States", "US": "United States",
@@ -100,11 +76,18 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
}), }),
vol.Optional( vol.Optional(
"enable_price_tracking", "enable_price_tracking",
default=self.config_entry.data.get("enable_price_tracking", True) default=self.config_entry.options.get("enable_price_tracking", True)
): bool, ): bool,
vol.Optional( vol.Optional(
"enable_image_search", "enable_image_search",
default=self.config_entry.data.get("enable_image_search", True) default=self.config_entry.options.get("enable_image_search", True)
): bool, ): 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."
}
) )