mirror of
https://github.com/thekiwismarthome/shopping-list-manager.git
synced 2026-05-01 11:46:30 +00:00
Update config_flow.py
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
"""Config flow for Shopping List Manager."""
|
"""Config flow for Shopping List Manager."""
|
||||||
|
import voluptuous as vol
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.core import callback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
@@ -9,6 +11,10 @@ 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
|
||||||
@@ -16,10 +22,71 @@ 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:
|
||||||
return self.async_create_entry(
|
# Store initial list name
|
||||||
title="Shopping List Manager",
|
self._data["initial_list_name"] = user_input.get("list_name", "Shopping List")
|
||||||
data={}
|
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",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Show simple form
|
async def async_step_features(self, user_input=None):
|
||||||
return self.async_show_form(step_id="user")
|
"""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(
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user