Skip to content

Commit d7ce9ba

Browse files
committed
fix: some misc bug changes
1 parent 67f9ed6 commit d7ce9ba

File tree

3 files changed

+12
-100
lines changed

3 files changed

+12
-100
lines changed

roborock/protocol.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,11 @@ def decode(bytes_data: bytes) -> list[RoborockMessage]:
517517
return decode
518518

519519

520-
def create_local_encoder(
521-
local_key: str, connect_nonce: int | None = None, ack_nonce: int | None = None, prefixed: bool = True
522-
) -> Encoder:
520+
def create_local_encoder(local_key: str, connect_nonce: int | None = None, ack_nonce: int | None = None) -> Encoder:
523521
"""Create an encoder for local API messages."""
524522

525523
def encode(message: RoborockMessage) -> bytes:
526524
"""Called when data is sent to the transport."""
527-
return MessageParser.build(
528-
message, local_key=local_key, connect_nonce=connect_nonce, ack_nonce=ack_nonce, prefixed=prefixed
529-
)
525+
return MessageParser.build(message, local_key=local_key, connect_nonce=connect_nonce, ack_nonce=ack_nonce)
530526

531527
return encode

roborock/version_1_apis/roborock_local_client_v1.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ def __init__(self, device_data: DeviceData, queue_timeout: int = 4, version: str
6363
self._version = version
6464
self._connect_nonce: int | None = None
6565
self._ack_nonce: int | None = None
66-
self._encoder: Encoder = create_local_encoder(device_data.device.local_key)
67-
self._decoder: Decoder = create_local_decoder(device_data.device.local_key)
66+
if version == "L01":
67+
self._set_l01_encoder_decoder()
68+
else:
69+
self._encoder: Encoder = create_local_encoder(device_data.device.local_key)
70+
self._decoder: Decoder = create_local_decoder(device_data.device.local_key)
6871
self.queue_timeout = queue_timeout
6972
self._logger = RoborockLoggerAdapter(device_data.device.name, _LOGGER)
7073

@@ -121,10 +124,9 @@ async def async_disconnect(self) -> None:
121124
async with self._mutex:
122125
self._sync_disconnect()
123126

124-
def _reinitialize_encoder_decoder(self):
125-
self._encoder = create_local_encoder(
126-
self.device_info.device.local_key, self._connect_nonce, self._ack_nonce, prefixed=False
127-
)
127+
def _set_l01_encoder_decoder(self):
128+
"""Tell the system to use the L01 encoder/decoder."""
129+
self._encoder = create_local_encoder(self.device_info.device.local_key, self._connect_nonce, self._ack_nonce)
128130
self._decoder = create_local_decoder(self.device_info.device.local_key, self._connect_nonce, self._ack_nonce)
129131

130132
async def _do_hello(self, version: str) -> bool:
@@ -145,13 +147,13 @@ async def _do_hello(self, version: str) -> bool:
145147
)
146148
if response.version.decode() == "L01":
147149
self._ack_nonce = response.random
148-
self._reinitialize_encoder_decoder()
150+
self._set_l01_encoder_decoder()
149151
self._version = version
150152
self._logger.debug(f"Client {self.device_info.device.duid} speaks the {version} protocol.")
151153
return True
152154
except RoborockException as e:
153155
self._logger.debug(
154-
f"Client {self.device_info.device.duid} does not respond or does not speak the {version} protocol. {e}"
156+
f"Client {self.device_info.device.duid} did not respond or does not speak the {version} protocol. {e}"
155157
)
156158
return False
157159

@@ -191,7 +193,6 @@ async def _send_command(
191193
raise RoborockException(f"Method {method} is not supported over local connection")
192194
if self._version == "L01":
193195
request_id = get_next_int(10000, 999999)
194-
# For L01, the payload is a JSON string with a "dps" field.
195196
dps_payload = {
196197
"id": request_id,
197198
"method": method,
@@ -208,7 +209,6 @@ async def _send_command(
208209
version=self._version.encode(),
209210
timestamp=ts,
210211
)
211-
roborock_message.seq = request_id
212212
self._logger.debug("Building message id %s for method %s", request_id, method)
213213
return await self._send_message(
214214
roborock_message,

tests/test_local_api_l01.py

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

0 commit comments

Comments
 (0)