1010
1111from roborock .api import RoborockClient , SPECIAL_COMMANDS
1212from roborock .containers import RoborockLocalDeviceInfo
13- from roborock .exceptions import RoborockTimeout , CommandVacuumError
13+ from roborock .exceptions import RoborockTimeout , CommandVacuumError , RoborockConnectionException
1414from roborock .typing import RoborockCommand
1515from roborock .util import get_running_loop_or_create_one
1616
@@ -105,18 +105,23 @@ async def _main_coro(self):
105105 await self .on_message (self .device_id , message )
106106 except Exception as e :
107107 _LOGGER .exception (e )
108- except BrokenPipeError :
108+ except BrokenPipeError as e :
109+ _LOGGER .exception (e )
109110 await self .disconnect ()
110111
111112 async def connect (self ):
112113 async with self ._mutex :
113114 if not self .is_connected or self .socket .is_closed :
114115 self .socket = RoborockSocket (socket .AF_INET , socket .SOCK_STREAM )
115116 self .socket .setblocking (False )
116- async with async_timeout .timeout (self .timeout ):
117- _LOGGER .info (f"Connecting to { self .ip } " )
118- await self .loop .sock_connect (self .socket , (self .ip , 58867 ))
119- self .is_connected = True
117+ try :
118+ async with async_timeout .timeout (self .timeout ):
119+ _LOGGER .info (f"Connecting to { self .ip } " )
120+ await self .loop .sock_connect (self .socket , (self .ip , 58867 ))
121+ self .is_connected = True
122+ except Exception as e :
123+ await self .disconnect ()
124+ raise RoborockConnectionException (f"Failed connecting to { self .ip } " ) from e
120125 self .loop .create_task (self ._main_coro ())
121126
122127 async def disconnect (self ):
@@ -134,6 +139,7 @@ async def send_message(self, data: bytes):
134139 raise RoborockTimeout (
135140 f"Timeout after { self .timeout } seconds waiting for response"
136141 ) from None
137- except BrokenPipeError :
142+ except BrokenPipeError as e :
143+ _LOGGER .exception (e )
138144 await self .disconnect ()
139145 return response
0 commit comments