10
10
from ..api import RoborockClient
11
11
from ..exceptions import RoborockConnectionException , RoborockException , VacuumError
12
12
from ..protocol import Decoder , Encoder , create_local_decoder , create_local_encoder
13
- from ..protocols .v1_protocol import encode_local_payload
13
+ from ..protocols .v1_protocol import RequestMessage
14
14
from ..roborock_message import RoborockMessage , RoborockMessageProtocol
15
15
from ..util import RoborockLoggerAdapter
16
16
from .roborock_client_v1 import CLOUD_REQUIRED , RoborockClientV1
@@ -123,12 +123,20 @@ async def async_disconnect(self) -> None:
123
123
124
124
async def hello (self ):
125
125
try :
126
- return await self ._send_message (_HELLO_REQUEST_MESSAGE )
126
+ return await self ._send_message (
127
+ roborock_message = _HELLO_REQUEST_MESSAGE ,
128
+ request_id = _HELLO_REQUEST_MESSAGE .seq ,
129
+ response_protocol = RoborockMessageProtocol .HELLO_RESPONSE ,
130
+ )
127
131
except Exception as e :
128
132
self ._logger .error (e )
129
133
130
134
async def ping (self ) -> None :
131
- await self ._send_message (_PING_REQUEST_MESSAGE )
135
+ await self ._send_message (
136
+ roborock_message = _PING_REQUEST_MESSAGE ,
137
+ request_id = _PING_REQUEST_MESSAGE .seq ,
138
+ response_protocol = RoborockMessageProtocol .PING_RESPONSE ,
139
+ )
132
140
133
141
def _send_msg_raw (self , data : bytes ):
134
142
try :
@@ -145,27 +153,26 @@ async def _send_command(
145
153
):
146
154
if method in CLOUD_REQUIRED :
147
155
raise RoborockException (f"Method { method } is not supported over local connection" )
148
-
149
- roborock_message = encode_local_payload (method , params )
150
- self ._logger .debug ("Building message id %s for method %s" , roborock_message .get_request_id (), method )
151
- return await self ._send_message (roborock_message , method , params )
156
+ request_message = RequestMessage (method = method , params = params )
157
+ roborock_message = request_message .encode_message (RoborockMessageProtocol .GENERAL_REQUEST )
158
+ self ._logger .debug ("Building message id %s for method %s" , request_message .request_id , method )
159
+ return await self ._send_message (
160
+ roborock_message ,
161
+ request_id = request_message .request_id ,
162
+ response_protocol = RoborockMessageProtocol .GENERAL_REQUEST ,
163
+ method = method ,
164
+ params = params ,
165
+ )
152
166
153
167
async def _send_message (
154
168
self ,
155
169
roborock_message : RoborockMessage ,
170
+ request_id : int ,
171
+ response_protocol : int ,
156
172
method : str | None = None ,
157
173
params : list | dict | int | None = None ,
158
174
) -> RoborockMessage :
159
175
await self .validate_connection ()
160
- request_id : int | None
161
- if not method or not method .startswith ("get" ):
162
- request_id = roborock_message .seq
163
- response_protocol = request_id + 1
164
- else :
165
- request_id = roborock_message .get_request_id ()
166
- response_protocol = RoborockMessageProtocol .GENERAL_REQUEST
167
- if request_id is None :
168
- raise RoborockException (f"Failed build message { roborock_message } " )
169
176
msg = self ._encoder (roborock_message )
170
177
if method :
171
178
self ._logger .debug (f"id={ request_id } Requesting method { method } with { params } " )
0 commit comments