77import re
88from typing import Any
99
10- import async_timeout
10+ import asyncio
11+
1112import voluptuous as vol
1213from homeassistant import config_entries
1314from homeassistant .const import (
1415 CONF_NAME ,
1516 CONF_TIMEOUT ,
1617 CONF_TYPE ,
1718)
18- from homeassistant .data_entry_flow import FlowResult
19+ from homeassistant .config_entries import ConfigFlowResult
1920from homeassistant .helpers import aiohttp_client
2021from homeassistant .helpers .selector import (
2122 BooleanSelector ,
@@ -227,7 +228,7 @@ async def _validate_access_token(session, token: str, timeout: int = 30) -> tupl
227228 "Authorization" : normalized ,
228229 }
229230 try :
230- async with async_timeout .timeout (timeout ):
231+ async with asyncio .timeout (timeout ):
231232 async with session .get (
232233 "https://api.clp.com.hk/ts1/ms/profile/accountdetails/myServicesCA" ,
233234 headers = headers ,
@@ -247,21 +248,20 @@ async def _validate_access_token(session, token: str, timeout: int = 30) -> tupl
247248class CLPHKOptionsFlowHandler (config_entries .OptionsFlow ):
248249 """Options flow: tokens -> options."""
249250
250- def __init__ (self , config_entry : config_entries .ConfigEntry ) -> None :
251- self .config_entry = config_entry
252- self ._merged_data = {** config_entry .data , ** config_entry .options }
251+ def __init__ (self ) -> None :
253252 self ._pending : dict [str , Any ] = {}
254253
255- async def async_step_init (self , user_input = None ) -> FlowResult :
254+ async def async_step_init (self , user_input = None ) -> ConfigFlowResult :
256255 return await self .async_step_tokens (user_input )
257256
258- async def async_step_tokens (self , user_input = None ) -> FlowResult :
257+ async def async_step_tokens (self , user_input = None ) -> ConfigFlowResult :
259258 errors : dict [str , str ] = {}
260259 if user_input is not None :
261260 access_token_input = user_input [CONF_ACCESS_TOKEN ]
262261 refresh_token_input = user_input [CONF_REFRESH_TOKEN ]
262+ merged = {** self .config_entry .data , ** self .config_entry .options }
263263 session = aiohttp_client .async_get_clientsession (self .hass )
264- timeout = int (self . _merged_data .get (CONF_TIMEOUT , 30 ))
264+ timeout = int (merged .get (CONF_TIMEOUT , 30 ))
265265 normalized_access_token , error_key = await _validate_access_token (
266266 session = session ,
267267 token = access_token_input ,
@@ -279,7 +279,7 @@ async def async_step_tokens(self, user_input=None) -> FlowResult:
279279 self ._pending [CONF_REFRESH_TOKEN ] = normalized_refresh_token
280280 return await self .async_step_options ()
281281
282- defaults = self ._merged_data
282+ defaults = { ** self .config_entry . data , ** self . config_entry . options }
283283 return self .async_show_form (
284284 step_id = "tokens" ,
285285 data_schema = vol .Schema (
@@ -291,7 +291,7 @@ async def async_step_tokens(self, user_input=None) -> FlowResult:
291291 errors = errors ,
292292 )
293293
294- async def async_step_options (self , user_input = None ) -> FlowResult :
294+ async def async_step_options (self , user_input = None ) -> ConfigFlowResult :
295295 if user_input is not None :
296296 self .hass .config_entries .async_update_entry (
297297 self .config_entry ,
@@ -307,7 +307,7 @@ async def async_step_options(self, user_input=None) -> FlowResult:
307307
308308 return self .async_show_form (
309309 step_id = "options" ,
310- data_schema = _build_options_schema (self ._merged_data ),
310+ data_schema = _build_options_schema ({ ** self .config_entry . data , ** self . config_entry . options } ),
311311 errors = {},
312312 )
313313
@@ -320,10 +320,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain="clphk"):
320320 def __init__ (self ) -> None :
321321 self ._pending : dict [str , Any ] = {}
322322
323- async def async_step_user (self , user_input : dict [str , Any ] | None = None ) -> FlowResult :
323+ async def async_step_user (self , user_input : dict [str , Any ] | None = None ) -> ConfigFlowResult :
324324 return await self .async_step_tokens (user_input )
325325
326- async def async_step_tokens (self , user_input : dict [str , Any ] | None = None ) -> FlowResult :
326+ async def async_step_tokens (self , user_input : dict [str , Any ] | None = None ) -> ConfigFlowResult :
327327 errors : dict [str , str ] = {}
328328 if user_input is not None :
329329 access_token_input = user_input [CONF_ACCESS_TOKEN ]
@@ -357,7 +357,7 @@ async def async_step_tokens(self, user_input: dict[str, Any] | None = None) -> F
357357 errors = errors ,
358358 )
359359
360- async def async_step_options (self , user_input : dict [str , Any ] | None = None ) -> FlowResult :
360+ async def async_step_options (self , user_input : dict [str , Any ] | None = None ) -> ConfigFlowResult :
361361 if user_input is not None :
362362 data = {
363363 ** user_input ,
@@ -374,4 +374,4 @@ async def async_step_options(self, user_input: dict[str, Any] | None = None) ->
374374
375375 @staticmethod
376376 def async_get_options_flow (config_entry ):
377- return CLPHKOptionsFlowHandler (config_entry )
377+ return CLPHKOptionsFlowHandler ()
0 commit comments