4
4
from typing import Any , Dict , Optional
5
5
6
6
from homeassistant .config_entries import ConfigEntry , ConfigFlow , OptionsFlow
7
- from homeassistant .core import callback
8
7
9
8
from .const import DOMAIN
10
9
from .integrations .fireflyiii_config import FireflyiiiConfig , FireflyiiiConfigSchema
11
10
11
+ # from homeassistant.core import callback
12
+
13
+
12
14
_LOGGER = logging .getLogger (__name__ )
13
15
14
16
15
17
class FireflyiiiConfigFlow (ConfigFlow , domain = DOMAIN ): # type: ignore
16
18
"""FireflyIII Integration config flow."""
17
19
18
- VERSION = 2
20
+ VERSION = 1
19
21
MINOR_VERSION = 0
20
22
21
23
data : FireflyiiiConfig
@@ -79,11 +81,61 @@ async def async_step_config(self, user_input: Optional[Dict[str, Any]] = None):
79
81
errors = errors ,
80
82
)
81
83
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)
87
139
88
140
89
141
class OptionsFlowHandler (OptionsFlow ):
@@ -101,6 +153,8 @@ async def async_step_init(
101
153
"""Manage the options for the custom component."""
102
154
errors : Dict [str , str ] = {}
103
155
156
+ await FireflyiiiConfigSchema .data_source ().get_api ()
157
+
104
158
if user_input is not None :
105
159
if not errors :
106
160
return self .async_create_entry (title = "" , data = user_input )
0 commit comments