10
10
11
11
from roborock .api import RoborockClient , SPECIAL_COMMANDS
12
12
from roborock .containers import RoborockLocalDeviceInfo
13
- from roborock .exceptions import RoborockTimeout , CommandVacuumError
13
+ from roborock .exceptions import RoborockTimeout , CommandVacuumError , RoborockConnectionException
14
14
from roborock .typing import RoborockCommand
15
15
from roborock .util import get_running_loop_or_create_one
16
16
@@ -105,18 +105,23 @@ async def _main_coro(self):
105
105
await self .on_message (self .device_id , message )
106
106
except Exception as e :
107
107
_LOGGER .exception (e )
108
- except BrokenPipeError :
108
+ except BrokenPipeError as e :
109
+ _LOGGER .exception (e )
109
110
await self .disconnect ()
110
111
111
112
async def connect (self ):
112
113
async with self ._mutex :
113
114
if not self .is_connected or self .socket .is_closed :
114
115
self .socket = RoborockSocket (socket .AF_INET , socket .SOCK_STREAM )
115
116
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
120
125
self .loop .create_task (self ._main_coro ())
121
126
122
127
async def disconnect (self ):
@@ -134,6 +139,7 @@ async def send_message(self, data: bytes):
134
139
raise RoborockTimeout (
135
140
f"Timeout after { self .timeout } seconds waiting for response"
136
141
) from None
137
- except BrokenPipeError :
142
+ except BrokenPipeError as e :
143
+ _LOGGER .exception (e )
138
144
await self .disconnect ()
139
145
return response
0 commit comments