Skip to content

Commit d6e3b34

Browse files
fix: code cleaning
1 parent 82c96e1 commit d6e3b34

File tree

6 files changed

+18
-41
lines changed

6 files changed

+18
-41
lines changed

roborock/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from roborock.api import RoborockApiClient
44
from roborock.cloud_api import RoborockMqttClient
5+
from roborock.local_api import RoborockLocalClient
56
from roborock.containers import *
67
from roborock.exceptions import *
78
from roborock.typing import *

roborock/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _get_msg_raw(self, device_id, protocol, timestamp, payload, prefix='') -> by
158158
def _get_payload(
159159
self, method: RoborockCommand, params: list = None
160160
):
161-
timestamp = 1680196427
161+
timestamp = math.floor(time.time())
162162
request_id = self._id_counter
163163
self._id_counter += 1
164164
inner = {
@@ -255,7 +255,7 @@ async def get_prop(self, device_id: str) -> RoborockDeviceProp:
255255
device_id, clean_summary.records[0]
256256
)
257257
dock_summary = None
258-
if status.dock_type != RoborockDockType.NO_DOCK:
258+
if status and status.dock_type != RoborockDockType.NO_DOCK:
259259
dock_summary = await self.get_dock_summary(device_id, status.dock_type)
260260
if any([status, dnd_timer, clean_summary, consumable]):
261261
return RoborockDeviceProp(

roborock/local_api.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import asyncio
34
import logging
45
import socket
56

@@ -8,16 +9,17 @@
89
from roborock.api import RoborockClient
910
from roborock.typing import RoborockCommand
1011
from roborock.util import get_running_loop_or_create_one
12+
from roborock.exceptions import RoborockTimeout
1113

1214
secured_prefix = 199
1315
_LOGGER = logging.getLogger(__name__)
1416

1517

1618
class RoborockLocalClient(RoborockClient):
1719

18-
def __init__(self, endpoint: str, device_localkey: dict[str, str]):
20+
def __init__(self, ip: str, endpoint: str, device_localkey: dict[str, str]):
1921
super().__init__(endpoint, device_localkey, True)
20-
self.listener = RoborockSocketListener("192.168.1.232", super()._decode_msg)
22+
self.listener = RoborockSocketListener(ip, super()._decode_msg)
2123

2224
async def async_connect(self):
2325
await self.listener.connect()
@@ -54,9 +56,14 @@ async def connect(self):
5456

5557
async def send_message(self, data: bytes, local_key: str):
5658
response = {}
57-
async with async_timeout.timeout(self.timeout):
58-
await self.loop.sock_sendall(self.socket, data)
59-
while response.get('protocol') != 4:
60-
message = await self.loop.sock_recv(self.socket, 4096)
61-
response = self.on_message(message, local_key)
59+
try:
60+
async with async_timeout.timeout(self.timeout):
61+
await self.loop.sock_sendall(self.socket, data)
62+
while response.get('protocol') != 4:
63+
message = await self.loop.sock_recv(self.socket, 4096)
64+
response = self.on_message(message, local_key)
65+
except (asyncio.TimeoutError, asyncio.CancelledError):
66+
raise RoborockTimeout(
67+
f"Timeout after {self.timeout} seconds waiting for response"
68+
) from None
6269
return response

roborock/offline/__init__.py

Whitespace-only changes.

roborock/offline/offline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
async def main():
1212
device_id = "1r9W0cAmDZ2COuVekgRhKA"
13-
client = RoborockLocalClient(endpoint, {
13+
client = RoborockLocalClient(local_ip, endpoint, {
1414
"1r9W0cAmDZ2COuVekgRhKA": local_key
1515
})
1616
await client.async_connect()

roborock/offline/socket_listener.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)