@@ -103,21 +103,25 @@ def __init__(self, endpoint: str, device_localkey: dict[str, str]) -> None:
103103 self ._waiting_queue : dict [int , RoborockQueue ] = {}
104104 self ._status_listeners : list [Callable [[str , str ], None ]] = []
105105
106+ def add_status_listener (self , callback : Callable [[str , str ], None ]):
107+ self ._status_listeners .append (callback )
108+
106109 def _decode_msg (self , msg : bytes , local_key : str ) -> dict [str , Any ]:
107110 if msg [4 :7 ] == "1.0" .encode ():
108111 msg = msg [4 :]
109112 elif msg [0 :3 ] != "1.0" .encode ():
110113 raise RoborockException (f"Unknown protocol version { msg [0 :3 ]} " )
111114 if len (msg ) == 17 :
112- [version , _seq , _random , timestamp , protocol ] = struct .unpack (
115+ [version , request_id , _random , timestamp , protocol ] = struct .unpack (
113116 "!3sIIIH" , msg [0 :17 ]
114117 )
115118 return {
116119 "version" : version ,
120+ "request_id" : request_id ,
117121 "timestamp" : timestamp ,
118122 "protocol" : protocol ,
119123 }
120- [version , _seq , _random , timestamp , protocol , payload_len ] = struct .unpack (
124+ [version , request_id , _random , timestamp , protocol , payload_len ] = struct .unpack (
121125 "!3sIIIHH" , msg [0 :19 ]
122126 )
123127 extra_len = len (msg ) - 23 - payload_len
@@ -132,20 +136,21 @@ def _decode_msg(self, msg: bytes, local_key: str) -> dict[str, Any]:
132136 decrypted_payload = unpad (decipher .decrypt (payload ), AES .block_size ) if payload else extra
133137 return {
134138 "version" : version ,
139+ "request_id" : request_id ,
135140 "timestamp" : timestamp ,
136141 "protocol" : protocol ,
137142 "payload" : decrypted_payload
138143 }
139144
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 :
141146 local_key = self .device_localkey [device_id ]
142147 aes_key = md5bin (encode_timestamp (timestamp ) + local_key + self ._salt )
143148 cipher = AES .new (aes_key , AES .MODE_ECB )
144149 encrypted = cipher .encrypt (pad (payload , AES .block_size ))
145150 encrypted_len = len (encrypted )
146151 values = [
147152 "1.0" .encode (),
148- self . _seq ,
153+ request_id ,
149154 self ._random ,
150155 timestamp ,
151156 protocol ,
0 commit comments