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
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",
# Create entry with default country
return self.async_create_entry(
title="Shopping List Manager",
data={"country": "NZ"}, # Default to NZ
options={
"country": "NZ",
"enable_price_tracking": True,
"enable_image_search": True,
"metric_units_only": True,
}
)
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=self._data
)
# 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."
}
)