Skip to content

Commit cdd0ea7

Browse files
fix: improving logs
1 parent 97bf500 commit cdd0ea7

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

roborock/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ async def _async_response(self, request_id: int, protocol_id: int = 0) -> tuple[
189189
(response, err) = await queue.async_get(QUEUE_TIMEOUT)
190190
return response, err
191191
except (asyncio.TimeoutError, asyncio.CancelledError):
192-
raise RoborockTimeout(f"Timeout after {QUEUE_TIMEOUT} seconds waiting for response") from None
192+
raise RoborockTimeout(f"id={request_id} Timeout after {QUEUE_TIMEOUT} seconds") from None
193193
finally:
194194
del self._waiting_queue[request_id]
195195

roborock/cloud_api.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ def on_connect(self, *args, **kwargs):
5656
_, __, ___, rc, ____ = args
5757
connection_queue = self._waiting_queue.get(CONNECT_REQUEST_ID)
5858
if rc != mqtt.MQTT_ERR_SUCCESS:
59-
message = f"Failed to connect (rc: {rc})"
59+
message = f"Failed to connect ({mqtt.error_string(rc)})"
6060
_LOGGER.error(message)
6161
if connection_queue:
62-
connection_queue.resolve((None, VacuumError(rc, message)))
62+
connection_queue.resolve((None, VacuumError(message)))
6363
return
6464
_LOGGER.info(f"Connected to mqtt {self._mqtt_host}:{self._mqtt_port}")
6565
topic = f"rr/m/o/{self._mqtt_user}/{self._hashed_user}/{self.device_info.device.duid}"
6666
(result, mid) = self.subscribe(topic)
6767
if result != 0:
68-
message = f"Failed to subscribe (rc: {result})"
68+
message = f"Failed to subscribe ({mqtt.error_string(rc)})"
6969
_LOGGER.error(message)
7070
if connection_queue:
71-
connection_queue.resolve((None, VacuumError(rc, message)))
71+
connection_queue.resolve((None, VacuumError(message)))
7272
return
7373
_LOGGER.info(f"Subscribed to topic {topic}")
7474
if connection_queue:
@@ -85,7 +85,7 @@ def on_message(self, *args, **kwargs):
8585
def on_disconnect(self, *args, **kwargs):
8686
_, __, rc, ___ = args
8787
try:
88-
super().on_connection_lost(RoborockException(f"(rc: {rc})"))
88+
super().on_connection_lost(RoborockException(mqtt.error_string(rc)))
8989
if rc == mqtt.MQTT_ERR_PROTOCOL:
9090
self.update_client_id()
9191
connection_queue = self._waiting_queue.get(DISCONNECT_REQUEST_ID)
@@ -114,7 +114,7 @@ def sync_disconnect(self) -> bool:
114114
_LOGGER.info("Disconnecting from mqtt")
115115
rc = super().disconnect()
116116
if rc not in [mqtt.MQTT_ERR_SUCCESS, mqtt.MQTT_ERR_NO_CONN]:
117-
raise RoborockException(f"Failed to disconnect (rc:{rc})")
117+
raise RoborockException(f"Failed to disconnect ({mqtt.error_string(rc)})")
118118
return rc == mqtt.MQTT_ERR_SUCCESS
119119

120120
def sync_connect(self) -> bool:
@@ -146,7 +146,7 @@ async def async_connect(self) -> None:
146146
def _send_msg_raw(self, msg: bytes) -> None:
147147
info = self.publish(f"rr/m/i/{self._mqtt_user}/{self._hashed_user}/{self.device_info.device.duid}", msg)
148148
if info.rc != mqtt.MQTT_ERR_SUCCESS:
149-
raise RoborockException(f"Failed to publish (rc: {info.rc})")
149+
raise RoborockException(f"Failed to publish ({mqtt.error_string(info.rc)})")
150150

151151
async def send_command(self, method: RoborockCommand, params: Optional[list | dict] = None):
152152
await self.validate_connection()

roborock/exceptions.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ class RoborockBackoffException(RoborockException):
2020
class VacuumError(RoborockException):
2121
"""Class for vacuum errors."""
2222

23-
def __init__(self, code, message):
24-
self.code = code
25-
self.message = message
26-
super().__init__()
27-
28-
def __str__(self, *args, **kwargs): # real signature unknown
29-
"""Return str(self)."""
30-
return f"{self.code}: {self.message}"
31-
3223

3324
class CommandVacuumError(RoborockException):
3425
"""Class for command vacuum errors."""

roborock/local_api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ def build_roborock_message(self, method: RoborockCommand, params: Optional[list
8585
)
8686

8787
async def ping(self):
88-
roborock_message = RoborockMessage(protocol=AP_CONFIG, payload=b"")
89-
return (await self.send_message(roborock_message))[0]
88+
return await self.send_command(RoborockCommand.APP_WAKEUP_ROBOT)
9089

9190
async def send_command(self, method: RoborockCommand, params: Optional[list | dict] = None):
9291
roborock_message = self.build_roborock_message(method, params)

0 commit comments

Comments
 (0)