1313from typing import Any
1414
1515from roborock .callbacks import CallbackList
16- from roborock .data import HomeDataDevice , HomeDataProduct , RoborockErrorCode , RoborockStateCode
16+ from roborock .data import HomeDataDevice , HomeDataProduct
1717from roborock .diagnostics import redact_device_data
1818from roborock .exceptions import RoborockException
1919from roborock .roborock_message import (
@@ -235,7 +235,7 @@ def _on_message(self, message: RoborockMessage) -> None:
235235 return
236236
237237 # Only process messages that can contain protocol updates
238- # RPC_RESPONSE (102), GENERAL_REQUEST (4), and GENERAL_RESPONSE (5)
238+ # RPC_RESPONSE (102), and GENERAL_RESPONSE (5)
239239 if message .protocol not in {
240240 RoborockMessageProtocol .RPC_RESPONSE ,
241241 RoborockMessageProtocol .GENERAL_RESPONSE ,
@@ -246,7 +246,7 @@ def _on_message(self, message: RoborockMessage) -> None:
246246 return
247247
248248 try :
249- payload = json .loads (message .payload .decode ())
249+ payload = json .loads (message .payload .decode ("utf-8" ))
250250 dps = payload .get ("dps" , {})
251251
252252 if not dps :
@@ -260,7 +260,7 @@ def _on_message(self, message: RoborockMessage) -> None:
260260
261261 try :
262262 data_protocol = RoborockDataProtocol (int (data_point_number ))
263- self ._logger .debug (f "Got device update for { data_protocol .name } : { data_point } " )
263+ self ._logger .debug ("Got device update for %s: %s" , data_protocol .name , data_point )
264264 self ._handle_protocol_update (data_protocol , data_point )
265265 except ValueError :
266266 # Unknown protocol number
@@ -269,7 +269,7 @@ def _on_message(self, message: RoborockMessage) -> None:
269269 f"This may allow for faster updates in the future."
270270 )
271271 except (json .JSONDecodeError , UnicodeDecodeError , KeyError ) as ex :
272- self ._logger .debug (f "Failed to parse protocol message: { ex } " )
272+ self ._logger .debug ("Failed to parse protocol message: %s" , ex )
273273
274274 def _handle_protocol_update (self , protocol : RoborockDataProtocol , data_point : Any ) -> None :
275275 """Handle a protocol update for a specific data protocol.
@@ -280,22 +280,9 @@ def _handle_protocol_update(self, protocol: RoborockDataProtocol, data_point: An
280280 """
281281 # Handle status protocol updates
282282 if protocol in ROBOROCK_DATA_STATUS_PROTOCOL and self .v1_properties and self .v1_properties .status :
283- # Update the specific field in the status trait
284- match protocol :
285- case RoborockDataProtocol .ERROR_CODE :
286- self .v1_properties .status .error_code = RoborockErrorCode (data_point )
287- case RoborockDataProtocol .STATE :
288- self .v1_properties .status .state = RoborockStateCode (data_point )
289- case RoborockDataProtocol .BATTERY :
290- self .v1_properties .status .battery = data_point
291- case RoborockDataProtocol .CHARGE_STATUS :
292- self .v1_properties .status .charge_status = data_point
293- case _:
294- # There is also fan power and water box mode, but for now those are skipped
295- return
296-
297- self ._logger .debug ("Updated status.%s to %s" , protocol .name .lower (), data_point )
298- self .v1_properties .status .notify_update ()
283+ if self .v1_properties .status .handle_protocol_update (protocol , data_point ):
284+ self ._logger .debug ("Updated status.%s to %s" , protocol .name .lower (), data_point )
285+ self .v1_properties .status .notify_update ()
299286
300287 def diagnostic_data (self ) -> dict [str , Any ]:
301288 """Return diagnostics information about the device."""
0 commit comments