88import aiohttp
99import voluptuous as vol
1010
11- from homeassistant import config_entries
1211from homeassistant .components import network
12+ from homeassistant .config_entries import (
13+ ConfigEntry ,
14+ ConfigFlow as ConfigFlowBase ,
15+ ConfigFlowResult ,
16+ OptionsFlow ,
17+ ZeroconfServiceInfo ,
18+ )
1319from homeassistant .const import CONF_HOST , CONF_NAME
1420from homeassistant .core import callback
1521from homeassistant .data_entry_flow import FlowResult
2834)
2935
3036
31- class ConfigFlow (config_entries . ConfigFlow , domain = DOMAIN ): # type: ignore[call-arg]
37+ class ConfigFlow (ConfigFlowBase , domain = DOMAIN ): # type: ignore[call-arg]
3238 """Handle a config flow for Nintendo Switch CFW."""
3339
3440 VERSION = 1
@@ -40,13 +46,13 @@ def __init__(self) -> None:
4046
4147 async def async_step_user (
4248 self , user_input : dict [str , Any ] | None = None
43- ) -> FlowResult :
49+ ) -> ConfigFlowResult :
4450 """Handle the initial step."""
4551
4652 if user_input is not None :
4753 if user_input .get ("flow_type" ) == "manual" :
4854 return await self .async_step_manual_entry ()
49- return await self .async_step_discovery ()
55+ return await self .async_step_select_device ()
5056
5157 return self .async_show_form (
5258 step_id = "user" ,
@@ -59,9 +65,13 @@ async def async_step_user(
5965 ),
6066 )
6167
62- async def async_step_discovery (
68+ async def async_step_discovery (self , discovery_info : dict [str , Any ]) -> ConfigFlowResult :
69+ """Handle discovery."""
70+ return await self .async_step_select_device ()
71+
72+ async def async_step_select_device (
6373 self , user_input : dict [str , Any ] | None = None
64- ) -> FlowResult :
74+ ) -> ConfigFlowResult :
6575 """Scan for Nintendo Switch consoles in the background."""
6676 if user_input is not None :
6777 # We already have discovered devices, let the user select one
@@ -194,7 +204,7 @@ async def async_step_manual_entry(
194204 self ._host ,
195205 err .status ,
196206 )
197- except aiohttp .ClientError , asyncio .TimeoutError :
207+ except ( aiohttp .ClientError , asyncio .TimeoutError ) :
198208 errors ["base" ] = "cannot_connect"
199209 LOGGER .error ("Manual connection to %s timed out or failed" , self ._host )
200210 except Exception as err :
@@ -221,8 +231,8 @@ async def async_step_manual_entry(
221231 )
222232
223233 async def async_step_zeroconf (
224- self , discovery_info : config_entries . ZeroconfServiceInfo
225- ) -> FlowResult :
234+ self , discovery_info : ZeroconfServiceInfo
235+ ) -> ConfigFlowResult :
226236 """Handle zeroconf discovery."""
227237 self ._host = discovery_info .host
228238 self ._name = "Nintendo Switch"
@@ -282,7 +292,7 @@ async def async_step_discovery_confirm(
282292 self ._host ,
283293 err .status ,
284294 )
285- except aiohttp .ClientError , asyncio .TimeoutError :
295+ except ( aiohttp .ClientError , asyncio .TimeoutError ) :
286296 errors ["base" ] = "cannot_connect"
287297 LOGGER .error (
288298 "Discovery confirmation for %s timed out or failed" , self ._host
@@ -304,22 +314,18 @@ async def async_step_discovery_confirm(
304314 @staticmethod
305315 @callback
306316 def async_get_options_flow (
307- config_entry : config_entries . ConfigEntry ,
308- ) -> config_entries . OptionsFlow :
317+ config_entry : ConfigEntry ,
318+ ) -> OptionsFlow :
309319 """Create the options flow."""
310320 return OptionsFlowHandler (config_entry )
311321
312322
313- class OptionsFlowHandler (config_entries . OptionsFlow ):
323+ class OptionsFlowHandler (OptionsFlow ):
314324 """Handle an options flow for Nintendo Switch CFW."""
315325
316- def __init__ (self , config_entry : config_entries .ConfigEntry ) -> None :
317- """Initialize options flow."""
318- self .config_entry = config_entry
319-
320326 async def async_step_init (
321327 self , user_input : dict [str , Any ] | None = None
322- ) -> FlowResult :
328+ ) -> ConfigFlowResult :
323329 """Manage the options."""
324330 if user_input is not None :
325331 return self .async_create_entry (title = "" , data = user_input )
0 commit comments