1010
1111
1212class ConfigFlow (config_entries .ConfigFlow , domain = DOMAIN ):
13- """First start of integration settings ."""
13+ """Integration configuration ."""
1414 VERSION = 1
1515 CONNECTION_CLASS = config_entries .CONN_CLASS_LOCAL_PUSH
1616
@@ -39,7 +39,7 @@ async def async_step_user(self, user_input=None):
3939 return self .async_show_form (
4040 step_id = "user" ,
4141 data_schema = schema ,
42- errors = {"base" : "Could not connect to the specified EMA host. " },
42+ errors = {"base" : "Could not connect to the specified EMA host" },
4343 )
4444 return self .async_show_form (step_id = "user" , data_schema = schema )
4545
@@ -56,13 +56,16 @@ async def async_step_init(self, user_input=None):
5656 if not self .config_entry .options
5757 else self .config_entry .options
5858 )
59- _LOGGER .debug ("async_step_init with options : %s" , current_options )
59+ _LOGGER .debug ("async_step_init with configuration : %s" , current_options )
6060
6161 schema = vol .Schema ({
62- vol .Required (key , default = current_options .get (key )): str if key != "send_to_ema" else bool
62+ vol .Required (key , default = current_options .get (key )): (
63+ str if key != "send_to_ema" else bool
64+ )
6365 for key in KEYS
6466 })
6567
68+
6669 if user_input is not None :
6770 ema_host = user_input ["ema_host" ]
6871 if await self .validate_ip (ema_host ):
@@ -73,14 +76,20 @@ async def async_step_init(self, user_input=None):
7376 return self .async_show_form (
7477 step_id = "init" ,
7578 data_schema = schema ,
76- errors = {"base" : "Could not connect to the specified EMA host. " },
79+ errors = {"base" : "Could not connect to the specified EMA host" },
7780 )
7881 return self .async_show_form (step_id = "init" , data_schema = schema )
7982
8083 @staticmethod
8184 async def validate_ip (ip_address : str ) -> bool :
8285 try :
83- await asyncio .wait_for (asyncio .open_connection (ip_address , 8995 ), timeout = 5.0 )
86+ reader , writer = await asyncio .wait_for (
87+ asyncio .open_connection (ip_address , 8995 ),
88+ timeout = 3.0
89+ )
90+ # Close the connection neatly
91+ writer .close ()
92+ await writer .wait_closed ()
8493 return True
8594 except (OSError , asyncio .TimeoutError ):
8695 return False
0 commit comments