From 483846cf9b4d62c958240bb222789d490a439116 Mon Sep 17 00:00:00 2001 From: balgerion <133121849+balgerion@users.noreply.github.com> Date: Tue, 29 Apr 2025 16:36:45 +0200 Subject: [PATCH] Update config_flow.py --- custom_components/pstryk/config_flow.py | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/custom_components/pstryk/config_flow.py b/custom_components/pstryk/config_flow.py index 77f598c..ce71e36 100644 --- a/custom_components/pstryk/config_flow.py +++ b/custom_components/pstryk/config_flow.py @@ -1,11 +1,14 @@ +"""Config flow for Pstryk Energy integration.""" from homeassistant import config_entries import voluptuous as vol from .const import DOMAIN class PstrykConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): + """Handle a config flow for Pstryk Energy.""" VERSION = 2 async def async_step_user(self, user_input=None): + """Handle the initial step.""" errors = {} if user_input is not None: return self.async_create_entry( @@ -22,3 +25,35 @@ class PstrykConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): }), errors=errors ) + + @staticmethod + def async_get_options_flow(config_entry): + """Get the options flow for this handler.""" + return PstrykOptionsFlowHandler(config_entry) + + +class PstrykOptionsFlowHandler(config_entries.OptionsFlow): + """Handle Pstryk options.""" + + 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) + + options = { + vol.Required("buy_top", default=self.config_entry.options.get( + "buy_top", self.config_entry.data.get("buy_top", 5))): vol.All( + vol.Coerce(int), vol.Range(min=1, max=24)), + vol.Required("sell_top", default=self.config_entry.options.get( + "sell_top", self.config_entry.data.get("sell_top", 5))): vol.All( + vol.Coerce(int), vol.Range(min=1, max=24)), + } + + return self.async_show_form( + step_id="init", + data_schema=vol.Schema(options) + )