@@ -103,21 +103,25 @@ def __init__(self, endpoint: str, device_localkey: dict[str, str]) -> None:
103
103
self ._waiting_queue : dict [int , RoborockQueue ] = {}
104
104
self ._status_listeners : list [Callable [[str , str ], None ]] = []
105
105
106
+ def add_status_listener (self , callback : Callable [[str , str ], None ]):
107
+ self ._status_listeners .append (callback )
108
+
106
109
def _decode_msg (self , msg : bytes , local_key : str ) -> dict [str , Any ]:
107
110
if msg [4 :7 ] == "1.0" .encode ():
108
111
msg = msg [4 :]
109
112
elif msg [0 :3 ] != "1.0" .encode ():
110
113
raise RoborockException (f"Unknown protocol version { msg [0 :3 ]} " )
111
114
if len (msg ) == 17 :
112
- [version , _seq , _random , timestamp , protocol ] = struct .unpack (
115
+ [version , request_id , _random , timestamp , protocol ] = struct .unpack (
113
116
"!3sIIIH" , msg [0 :17 ]
114
117
)
115
118
return {
116
119
"version" : version ,
120
+ "request_id" : request_id ,
117
121
"timestamp" : timestamp ,
118
122
"protocol" : protocol ,
119
123
}
120
- [version , _seq , _random , timestamp , protocol , payload_len ] = struct .unpack (
124
+ [version , request_id , _random , timestamp , protocol , payload_len ] = struct .unpack (
121
125
"!3sIIIHH" , msg [0 :19 ]
122
126
)
123
127
extra_len = len (msg ) - 23 - payload_len
@@ -132,20 +136,21 @@ def _decode_msg(self, msg: bytes, local_key: str) -> dict[str, Any]:
132
136
decrypted_payload = unpad (decipher .decrypt (payload ), AES .block_size ) if payload else extra
133
137
return {
134
138
"version" : version ,
139
+ "request_id" : request_id ,
135
140
"timestamp" : timestamp ,
136
141
"protocol" : protocol ,
137
142
"payload" : decrypted_payload
138
143
}
139
144
140
- def _encode_msg (self , device_id , protocol , timestamp , payload , prefix = None ) -> bytes :
145
+ def _encode_msg (self , device_id , request_id , protocol , timestamp , payload , prefix = None ) -> bytes :
141
146
local_key = self .device_localkey [device_id ]
142
147
aes_key = md5bin (encode_timestamp (timestamp ) + local_key + self ._salt )
143
148
cipher = AES .new (aes_key , AES .MODE_ECB )
144
149
encrypted = cipher .encrypt (pad (payload , AES .block_size ))
145
150
encrypted_len = len (encrypted )
146
151
values = [
147
152
"1.0" .encode (),
148
- self . _seq ,
153
+ request_id ,
149
154
self ._random ,
150
155
timestamp ,
151
156
protocol ,
0 commit comments