Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions roborock/devices/local_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def _update_encoder_decoder(self, params: LocalChannelParams):
)
# Callback to decode messages and dispatch to subscribers
self._data_received: Callable[[bytes], None] = decoder_callback(self._decoder, self._subscribers, _LOGGER)
if self._protocol:
self._protocol.messages_cb = self._data_received
Comment thread
allenporter marked this conversation as resolved.
Outdated

async def _do_hello(self, local_protocol_version: LocalProtocolVersion) -> LocalChannelParams | None:
"""Perform the initial handshaking and return encoder params if successful."""
Expand Down Expand Up @@ -125,6 +127,13 @@ async def _hello(self):

raise RoborockException("Failed to connect to device with any known protocol")

@property
def protocol_version(self) -> LocalProtocolVersion:
"""Return the negotiated local protocol version, or a sensible default."""
if self._local_protocol_version is not None:
return self._local_protocol_version
return LocalProtocolVersion.V1
Comment thread
Lash-L marked this conversation as resolved.

@property
def is_connected(self) -> bool:
"""Check if the channel is currently connected."""
Expand Down
2 changes: 1 addition & 1 deletion roborock/devices/v1_rpc_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def create_local_rpc_channel(local_channel: LocalChannel) -> V1RpcChannel:
return PayloadEncodedV1RpcChannel(
"local",
local_channel,
lambda x: x.encode_message(RoborockMessageProtocol.GENERAL_REQUEST),
lambda x: x.encode_message(RoborockMessageProtocol.GENERAL_REQUEST, version=local_channel.protocol_version),
decode_rpc_response,
)

Expand Down
7 changes: 5 additions & 2 deletions roborock/protocols/v1_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ class RequestMessage:
request_id: int = field(default_factory=lambda: get_next_int(10000, 32767))

def encode_message(
self, protocol: RoborockMessageProtocol, security_data: SecurityData | None = None, version: str = "1.0"
self,
protocol: RoborockMessageProtocol,
security_data: SecurityData | None = None,
version: LocalProtocolVersion = LocalProtocolVersion.V1,
) -> RoborockMessage:
"""Convert the request message to a RoborockMessage."""
return RoborockMessage(
timestamp=self.timestamp,
protocol=protocol,
payload=self._as_payload(security_data=security_data),
version=version.encode(),
version=version.value.encode(),
)

def _as_payload(self, security_data: SecurityData | None) -> bytes:
Expand Down
Loading