1616class MQTTClient :
1717 def __init__ (
1818 self ,
19- user : str | None = None ,
20- pw : str | None = None ,
19+ username : str | None = None ,
20+ password : str | None = None ,
2121 host : str | None = "localhost" ,
2222 port : int | None = 1883 ,
2323 topic : str | None = None ,
@@ -26,11 +26,17 @@ def __init__(
2626 reconnect_rate : int = 2 ,
2727 max_reconnect_delay : int = 60 ,
2828 transport : str = "tcp" ,
29+ ** kwargs ,
2930 ):
31+ if "user" in kwargs :
32+ username = kwargs ["user" ]
33+ if "pw" in kwargs :
34+ password = kwargs ["pw" ]
35+
3036 self .topic = topic
3137
32- self ._user = user
33- self ._pw = pw
38+ self ._username = username
39+ self ._password = password
3440 self ._host = host
3541 self ._port = port
3642 self ._first_reconnect_delay = first_reconnect_delay
@@ -136,8 +142,8 @@ def connect(self) -> Client:
136142 client_id = f"flowerpower-{ random .randint (0 , 10000 )} " ,
137143 transport = self ._transport ,
138144 userdata = Munch (
139- user = self ._user ,
140- pw = self ._pw ,
145+ user = self ._username ,
146+ pw = self ._password ,
141147 host = self ._host ,
142148 port = self ._port ,
143149 topic = self .topic ,
@@ -148,8 +154,8 @@ def connect(self) -> Client:
148154 transport = self ._transport ,
149155 ),
150156 )
151- if self ._pw != "" and self ._user != "" :
152- client .username_pw_set (self ._user , self ._pw )
157+ if self ._password != "" and self ._username != "" :
158+ client .username_pw_set (self ._username , self ._password )
153159
154160 client .on_connect = self ._on_connect
155161 client .on_disconnect = self ._on_disconnect
0 commit comments