44from typing import Any , Dict , Optional
55
66from homeassistant .config_entries import ConfigEntry , ConfigFlow , OptionsFlow
7- from homeassistant .core import callback
87
98from .const import DOMAIN
109from .integrations .fireflyiii_config import FireflyiiiConfig , FireflyiiiConfigSchema
1110
11+ # from homeassistant.core import callback
12+
13+
1214_LOGGER = logging .getLogger (__name__ )
1315
1416
1517class FireflyiiiConfigFlow (ConfigFlow , domain = DOMAIN ): # type: ignore
1618 """FireflyIII Integration config flow."""
1719
18- VERSION = 2
20+ VERSION = 1
1921 MINOR_VERSION = 0
2022
2123 data : FireflyiiiConfig
@@ -79,11 +81,61 @@ async def async_step_config(self, user_input: Optional[Dict[str, Any]] = None):
7981 errors = errors ,
8082 )
8183
82- @staticmethod
83- @callback
84- def async_get_options_flow (config_entry ):
85- """Get the options flow for this handler."""
86- return OptionsFlowHandler (config_entry )
84+ async def async_step_reconfigure (self , user_input : dict [str , Any ] | None = None ):
85+ """Reconfig Flow"""
86+ errors : Dict [str , str ] = {}
87+ if user_input is not None :
88+ entry = self .hass .config_entries .async_get_entry (self .context ["entry_id" ])
89+ old_data = entry .data .copy ()
90+ old_data .update (user_input )
91+ fireflyiii_config = FireflyiiiConfig (old_data )
92+ fireflyiii_api = await fireflyiii_config .get_api ()
93+
94+ if not await fireflyiii_api .check_connection ():
95+ errors ["base" ] = "auth"
96+
97+ if not errors :
98+ self .data = fireflyiii_config
99+ FireflyiiiConfigSchema .set_data_source (self .data )
100+
101+ return self .async_show_form (
102+ step_id = "reconfigure2" ,
103+ data_schema = FireflyiiiConfigSchema .schema_reconfigure2 (),
104+ errors = errors ,
105+ )
106+
107+ return self .async_show_form (
108+ step_id = "reconfigure" ,
109+ data_schema = FireflyiiiConfigSchema .schema_reconfigure (),
110+ errors = errors ,
111+ )
112+
113+ async def async_step_reconfigure2 (self , user_input : dict [str , Any ] | None = None ):
114+ """Reconfig Flow"""
115+ errors : Dict [str , str ] = {}
116+ if user_input is not None :
117+ entry = self .hass .config_entries .async_get_entry (self .context ["entry_id" ])
118+ self .data .update (user_input )
119+
120+ if not errors :
121+ return self .async_update_reload_and_abort (
122+ entry ,
123+ title = self .data .name ,
124+ data = self .data ,
125+ reason = "reconfigure_successful" ,
126+ )
127+
128+ return self .async_show_form (
129+ step_id = "reconfigure2" ,
130+ data_schema = FireflyiiiConfigSchema .schema_reconfigure2 (),
131+ errors = errors ,
132+ )
133+
134+ # @staticmethod
135+ # @callback
136+ # def async_get_options_flow(config_entry):
137+ # """Get the options flow for this handler."""
138+ # return OptionsFlowHandler(config_entry)
87139
88140
89141class OptionsFlowHandler (OptionsFlow ):
@@ -101,6 +153,8 @@ async def async_step_init(
101153 """Manage the options for the custom component."""
102154 errors : Dict [str , str ] = {}
103155
156+ await FireflyiiiConfigSchema .data_source ().get_api ()
157+
104158 if user_input is not None :
105159 if not errors :
106160 return self .async_create_entry (title = "" , data = user_input )
0 commit comments