11"""Config flow for IsItPayday integration."""
22
33import logging
4+
45import aiohttp
56import voluptuous as vol
67from homeassistant import config_entries
1213
1314_LOGGER = logging .getLogger (__name__ )
1415
15- WEEKDAY_MAP = {
16- "Monday" : 0 ,
17- "Tuesday" : 1 ,
18- "Wednesday" : 2 ,
19- "Thursday" : 3 ,
20- "Friday" : 4
21- }
16+ WEEKDAY_MAP = {"Monday" : 0 , "Tuesday" : 1 , "Wednesday" : 2 , "Thursday" : 3 , "Friday" : 4 }
2217
2318
2419async def async_get_homeassistant_country (hass : HomeAssistant ) -> str | None :
@@ -83,10 +78,11 @@ async def async_step_reconfigure(self, user_input=None):
8378 async def async_step_user (self , user_input = None ):
8479 if user_input is None :
8580 self .country_list = await async_fetch_supported_countries ()
86- current_country = self .country or await async_get_homeassistant_country (self .hass ) or "DK"
81+ current_country = (
82+ self .country or await async_get_homeassistant_country (self .hass ) or "DK"
83+ )
8784 return self .async_show_form (
88- step_id = "user" ,
89- data_schema = self ._create_user_schema (current_country )
85+ step_id = "user" , data_schema = self ._create_user_schema (current_country )
9086 )
9187
9288 self .name = user_input [CONF_NAME ]
@@ -96,8 +92,7 @@ async def async_step_user(self, user_input=None):
9692 async def async_step_frequency (self , user_input = None ):
9793 if user_input is None :
9894 return self .async_show_form (
99- step_id = "frequency" ,
100- data_schema = self ._create_pay_frequency_schema ()
95+ step_id = "frequency" , data_schema = self ._create_pay_frequency_schema ()
10196 )
10297
10398 self .pay_frequency = user_input [CONF_PAY_FREQ ]
@@ -110,7 +105,7 @@ async def async_step_frequency(self, user_input=None):
110105 PAY_FREQ_SEMIANNUAL ,
111106 PAY_FREQ_ANNUAL ,
112107 PAY_FREQ_28_DAYS ,
113- PAY_FREQ_14_DAYS
108+ PAY_FREQ_14_DAYS ,
114109 ]:
115110 return await self .async_step_cycle_last_paydate ()
116111 elif self .pay_frequency == PAY_FREQ_WEEKLY :
@@ -121,8 +116,7 @@ async def async_step_frequency(self, user_input=None):
121116 async def async_step_monthly_day (self , user_input = None ):
122117 if user_input is None :
123118 return self .async_show_form (
124- step_id = "monthly_day" ,
125- data_schema = self ._create_monthly_day_schema ()
119+ step_id = "monthly_day" , data_schema = self ._create_monthly_day_schema ()
126120 )
127121
128122 self .pay_day = user_input [CONF_PAY_DAY ]
@@ -137,8 +131,7 @@ async def async_step_monthly_day(self, user_input=None):
137131 async def async_step_bank_offset (self , user_input = None ):
138132 if user_input is None :
139133 return self .async_show_form (
140- step_id = "bank_offset" ,
141- data_schema = self ._create_bank_offset_schema ()
134+ step_id = "bank_offset" , data_schema = self ._create_bank_offset_schema ()
142135 )
143136
144137 self .bank_offset = int (user_input [CONF_BANK_OFFSET ])
@@ -147,8 +140,7 @@ async def async_step_bank_offset(self, user_input=None):
147140 async def async_step_specific_day (self , user_input = None ):
148141 if user_input is None :
149142 return self .async_show_form (
150- step_id = "specific_day" ,
151- data_schema = self ._create_specific_day_schema ()
143+ step_id = "specific_day" , data_schema = self ._create_specific_day_schema ()
152144 )
153145
154146 self .pay_day = int (user_input [CONF_PAY_DAY ])
@@ -158,7 +150,7 @@ async def async_step_cycle_last_paydate(self, user_input=None):
158150 if user_input is None :
159151 return self .async_show_form (
160152 step_id = "cycle_last_paydate" ,
161- data_schema = self ._create_last_paydate_schema ()
153+ data_schema = self ._create_last_paydate_schema (),
162154 )
163155
164156 self .last_pay_date = user_input [CONF_LAST_PAY_DATE ]
@@ -167,8 +159,7 @@ async def async_step_cycle_last_paydate(self, user_input=None):
167159 async def async_step_weekly (self , user_input = None ):
168160 if user_input is None :
169161 return self .async_show_form (
170- step_id = "weekly" ,
171- data_schema = self ._create_weekly_schema ()
162+ step_id = "weekly" , data_schema = self ._create_weekly_schema ()
172163 )
173164
174165 self .pay_day = user_input [CONF_PAY_DAY ]
@@ -189,53 +180,85 @@ def _create_entry(self) -> FlowResult:
189180 if self .reconfig_entry :
190181 _LOGGER .info ("Updating existing entry: %s" , self .reconfig_entry .entry_id )
191182 self .hass .config_entries .async_update_entry (self .reconfig_entry , data = data )
192- self .hass .async_create_task (self .hass .config_entries .async_reload (self .reconfig_entry .entry_id ))
183+ self .hass .async_create_task (
184+ self .hass .config_entries .async_reload (self .reconfig_entry .entry_id )
185+ )
193186
194- self .hass .async_create_task (self .hass .services .async_call (
195- "persistent_notification" ,
196- "create" ,
197- {
198- "title" : "IsItPayday" ,
199- "message" : f"The configuration for '{ self .name } ' has been successfully updated."
200- }
201- ))
187+ self .hass .async_create_task (
188+ self .hass .services .async_call (
189+ "persistent_notification" ,
190+ "create" ,
191+ {
192+ "title" : "IsItPayday" ,
193+ "message" : f"The configuration for '{ self .name } ' has been successfully updated." ,
194+ },
195+ )
196+ )
202197
203198 return self .async_abort (reason = "reconfigured" )
204199
205200 return self .async_create_entry (title = self .name , data = data )
206201
207202 def _create_user_schema (self , default_country : str ) -> vol .Schema :
208- return vol .Schema ({
209- vol .Required (CONF_NAME , default = self .name or "" ): str ,
210- vol .Required (CONF_COUNTRY , default = default_country ): vol .In (self .country_list )
211- })
203+ return vol .Schema (
204+ {
205+ vol .Required (CONF_NAME , default = self .name or "" ): str ,
206+ vol .Required (CONF_COUNTRY , default = default_country ): vol .In (
207+ self .country_list
208+ ),
209+ }
210+ )
212211
213212 def _create_pay_frequency_schema (self ) -> vol .Schema :
214- return vol .Schema ({
215- vol .Required (CONF_PAY_FREQ , default = self .pay_frequency or PAY_FREQ_MONTHLY ): vol .In (PAY_FREQ_OPTIONS )
216- })
213+ return vol .Schema (
214+ {
215+ vol .Required (
216+ CONF_PAY_FREQ , default = self .pay_frequency or PAY_FREQ_MONTHLY
217+ ): vol .In (PAY_FREQ_OPTIONS )
218+ }
219+ )
217220
218221 def _create_monthly_day_schema (self ) -> vol .Schema :
219- return vol .Schema ({
220- vol .Required (CONF_PAY_DAY , default = self .pay_day or PAY_DAY_LAST_BANK_DAY ): vol .In (PAY_MONTHLY_OPTIONS )
221- })
222+ return vol .Schema (
223+ {
224+ vol .Required (
225+ CONF_PAY_DAY , default = self .pay_day or PAY_DAY_LAST_BANK_DAY
226+ ): vol .In (PAY_MONTHLY_OPTIONS )
227+ }
228+ )
222229
223230 def _create_bank_offset_schema (self ) -> vol .Schema :
224- return vol .Schema ({
225- vol .Required (CONF_BANK_OFFSET , default = self .bank_offset or 0 ): vol .In (range (0 , 11 ))
226- })
231+ return vol .Schema (
232+ {
233+ vol .Required (CONF_BANK_OFFSET , default = self .bank_offset or 0 ): vol .In (
234+ range (0 , 11 )
235+ )
236+ }
237+ )
227238
228239 def _create_specific_day_schema (self ) -> vol .Schema :
229- return vol .Schema ({
230- vol .Required (CONF_PAY_DAY , default = self .pay_day or 31 ): vol .In (range (1 , 32 ))
231- })
240+ return vol .Schema (
241+ {
242+ vol .Required (CONF_PAY_DAY , default = self .pay_day or 31 ): vol .In (
243+ range (1 , 32 )
244+ )
245+ }
246+ )
232247
233248 def _create_last_paydate_schema (self ) -> vol .Schema :
234- return vol .Schema ({
235- vol .Required (CONF_LAST_PAY_DATE , default = self .last_pay_date ): DateSelector ()
236- })
249+ return vol .Schema (
250+ {
251+ vol .Required (
252+ CONF_LAST_PAY_DATE , default = self .last_pay_date
253+ ): DateSelector ()
254+ }
255+ )
237256
238257 def _create_weekly_schema (self ) -> vol .Schema :
239- return vol .Schema ({
240- vol .Required (CONF_PAY_DAY , default = self .pay_day or "Monday" ): vol .In (WEEKDAY_OPTIONS )
241- })
258+ return vol .Schema (
259+ {
260+ vol .Required (CONF_PAY_DAY , default = self .pay_day or "Monday" ): vol .In (
261+ WEEKDAY_OPTIONS
262+ )
263+ }
264+ )
0 commit comments