88from typing import Any
99
1010import paho .mqtt .client as mqtt
11- from paho .mqtt .reasoncodes import ReasonCodes
11+
12+ # Mypy is not seeing this for some reason. It wants me to use the depreciated ReasonCodes
13+ from paho .mqtt .reasoncodes import ReasonCode # type: ignore
1214
1315from .api import KEEPALIVE , RoborockClient
1416from .containers import DeviceData , UserData
@@ -68,7 +70,8 @@ def __init__(self, user_data: UserData, device_info: DeviceData) -> None:
6870 self ._mqtt_client = _Mqtt ()
6971 self ._mqtt_client .on_connect = self ._mqtt_on_connect
7072 self ._mqtt_client .on_message = self ._mqtt_on_message
71- self ._mqtt_client .on_disconnect = self ._mqtt_on_disconnect
73+ # Due to the incorrect ReasonCode, it is confused by typing
74+ self ._mqtt_client .on_disconnect = self ._mqtt_on_disconnect # type: ignore
7275 if mqtt_params .tls :
7376 self ._mqtt_client .tls_set ()
7477
@@ -78,11 +81,17 @@ def __init__(self, user_data: UserData, device_info: DeviceData) -> None:
7881 self ._decoder : Decoder = create_mqtt_decoder (device_info .device .local_key )
7982 self ._encoder : Encoder = create_mqtt_encoder (device_info .device .local_key )
8083
81- def _mqtt_on_connect (self , * args , ** kwargs ):
82- rc : ReasonCodes = args [3 ]
84+ def _mqtt_on_connect (
85+ self ,
86+ client : mqtt .Client ,
87+ data : object ,
88+ flags : dict [str , int ],
89+ rc : ReasonCode ,
90+ properties : mqtt .Properties | None = None ,
91+ ):
8392 connection_queue = self ._waiting_queue .get (CONNECT_REQUEST_ID )
84- if rc != 0 :
85- message = f"Failed to connect ({ str ( rc ) } )"
93+ if rc . is_failure :
94+ message = f"Failed to connect ({ rc } )"
8695 self ._logger .error (message )
8796 if connection_queue :
8897 # These are the ReasonCodes relating to authorization issues.
@@ -116,10 +125,16 @@ def _mqtt_on_message(self, *args, **kwargs):
116125 except Exception as ex :
117126 self ._logger .exception (ex )
118127
119- def _mqtt_on_disconnect (self , * args , ** kwargs ):
120- _ , __ , rc , ___ = args
128+ def _mqtt_on_disconnect (
129+ self ,
130+ client : mqtt .Client ,
131+ data : object ,
132+ flags : dict [str , int ],
133+ rc : ReasonCode ,
134+ properties : mqtt .Properties | None = None ,
135+ ):
121136 try :
122- exc = RoborockException (str (rc )) if rc != mqtt . MQTT_ERR_SUCCESS else None
137+ exc = RoborockException (str (rc )) if rc . is_failure else None
123138 super ().on_connection_lost (exc )
124139 connection_queue = self ._waiting_queue .get (DISCONNECT_REQUEST_ID )
125140 if connection_queue :
0 commit comments