Skip to content

Commit 7e73eb2

Browse files
fix: adiing broken pipe exception log
1 parent 785b34c commit 7e73eb2

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

roborock/exceptions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ class RoborockException(BaseException):
66
class RoborockTimeout(RoborockException):
77
"""Class for Roborock timeout exceptions."""
88

9+
class RoborockConnectionException(RoborockException):
10+
"""Class for Roborock connection exceptions."""
11+
912
class RoborockBackoffException(RoborockException):
1013
"""Class for Roborock exceptions when many retries were made."""
1114

roborock/local_api.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from roborock.api import RoborockClient, SPECIAL_COMMANDS
1212
from roborock.containers import RoborockLocalDeviceInfo
13-
from roborock.exceptions import RoborockTimeout, CommandVacuumError
13+
from roborock.exceptions import RoborockTimeout, CommandVacuumError, RoborockConnectionException
1414
from roborock.typing import RoborockCommand
1515
from 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

Comments
 (0)