@@ -193,19 +193,23 @@ def __exit__(self, exception_type, exception_value, traceback):
193
193
self .deinit ()
194
194
195
195
def deinit (self ):
196
- """De-initializes the MQTT client and disconnects from
197
- the mqtt broker.
198
-
196
+ """De-initializes the MQTT client and disconnects from the mqtt broker.
199
197
"""
200
198
self .disconnect ()
201
199
202
200
def will_set (self , topic = None , payload = None , qos = 0 , retain = False ):
203
201
"""Sets the last will and testament properties. MUST be called before `connect()`.
204
202
205
203
:param str topic: MQTT Broker topic.
206
- :param str payload: Last will disconnection payload.
207
- :param int qos: Quality of Service level.
208
- :param bool retain: Specifies if the payload is to be retained when it is published.
204
+ :param int,float,str payload: Last will disconnection payload.
205
+ payloads of type int & float are converted to a string.
206
+ :param int qos: Quality of Service level, defaults to
207
+ zero. Conventional options are ``0`` (send at least once), ``1``
208
+ (send at most once), or ``2`` (send exactly once).
209
+
210
+ .. note:: Only options ``1`` or ``0`` are QoS levels supported by this library.
211
+ :param bool retain: Specifies if the payload is to be retained when
212
+ it is published.
209
213
"""
210
214
if self .logger is not None :
211
215
self .logger .debug ("Setting last will properties" )
@@ -226,7 +230,7 @@ def will_set(self, topic=None, payload=None, qos=0, retain=False):
226
230
def add_topic_callback (self , mqtt_topic , callback_method ):
227
231
"""Registers a callback_method for a specific MQTT topic.
228
232
229
- :param str mqtt_topic: MQTT topic.
233
+ :param str mqtt_topic: MQTT topic identifier .
230
234
:param str callback_method: Name of callback method.
231
235
"""
232
236
if mqtt_topic is None or callback_method is None :
@@ -236,7 +240,7 @@ def add_topic_callback(self, mqtt_topic, callback_method):
236
240
def remove_topic_callback (self , mqtt_topic ):
237
241
"""Removes a registered callback method.
238
242
239
- :param str mqtt_topic: MQTT topic.
243
+ :param str mqtt_topic: MQTT topic identifier string .
240
244
"""
241
245
if mqtt_topic is None :
242
246
raise ValueError ("MQTT Topic must be defined." )
@@ -249,8 +253,7 @@ def remove_topic_callback(self, mqtt_topic):
249
253
def on_message (self ):
250
254
"""Called when a new message has been received on a subscribed topic.
251
255
252
- Expected method signature is:
253
- on_message(client, topic, message)
256
+ Expected method signature is ``on_message(client, topic, message)``
254
257
"""
255
258
return self ._on_message
256
259
@@ -300,8 +303,7 @@ def connect(self, clean_session=True):
300
303
raise MMQTTException ("Invalid broker address defined." , e )
301
304
302
305
# Fixed Header
303
- fixed_header = bytearray ()
304
- fixed_header .append (0x10 )
306
+ fixed_header = bytearray ([0x10 ])
305
307
306
308
# NOTE: Variable header is
307
309
# MQTT_HDR_CONNECT = bytearray(b"\x04MQTT\x04\x02\0\0")
@@ -413,11 +415,13 @@ def publish(self, topic, msg, retain=False, qos=0):
413
415
"""Publishes a message to a topic provided.
414
416
415
417
:param str topic: Unique topic identifier.
416
- :param str msg: Data to send to the broker.
417
- :param int msg: Data to send to the broker.
418
- :param float msg: Data to send to the broker.
418
+ :param str,int,float msg: Data to send to the broker.
419
419
:param bool retain: Whether the message is saved by the broker.
420
- :param int qos: Quality of Service level for the message.
420
+ :param int qos: Quality of Service level for the message, defaults to
421
+ zero. Conventional options are ``0`` (send at least once), ``1``
422
+ (send at most once), or ``2`` (send exactly once).
423
+
424
+ .. note:: Only options ``1`` or ``0`` are QoS levels supported by this library.
421
425
422
426
Example of sending an integer, 3, to the broker on topic 'piVal'.
423
427
@@ -514,10 +518,16 @@ def subscribe(self, topic, qos=0):
514
518
"""Subscribes to a topic on the MQTT Broker.
515
519
This method can subscribe to one topics or multiple topics.
516
520
517
- :param str topic: Unique MQTT topic identifier.
518
- :param int qos: Quality of Service level for the topic, defaults to zero.
519
- :param tuple topic: Tuple containing topic identifier strings and qos level integers.
520
- :param list topic: List of tuples containing topic identifier strings and qos.
521
+ :param str,tuple,list topic: Unique MQTT topic identifier string. If
522
+ this is a `tuple`, then the tuple should contain topic identifier
523
+ string and qos level integer. If this is a `list`, then each list
524
+ element should be a tuple containing a topic identifier string and
525
+ qos level integer.
526
+ :param int qos: Quality of Service level for the topic, defaults to
527
+ zero. Conventional options are ``0`` (send at least once), ``1``
528
+ (send at most once), or ``2`` (send exactly once).
529
+
530
+ .. note:: Only options ``1`` or ``0`` are QoS levels supported by this library.
521
531
522
532
Example of subscribing a topic string.
523
533
@@ -593,8 +603,9 @@ def subscribe(self, topic, qos=0):
593
603
def unsubscribe (self , topic ):
594
604
"""Unsubscribes from a MQTT topic.
595
605
596
- :param str topic: Unique MQTT topic identifier.
597
- :param list topic: List of tuples containing topic identifier strings.
606
+ :param str,list topic: Unique MQTT topic identifier string or a list
607
+ of tuples, where each tuple contains an MQTT topic identier
608
+ string.
598
609
599
610
Example of unsubscribing from a topic string.
600
611
@@ -804,7 +815,7 @@ def _set_interface(self):
804
815
805
816
def is_connected (self ):
806
817
"""Returns MQTT client session status as True if connected, raises
807
- a MMQTTException if False.
818
+ a ` MMQTTException` if ` False` .
808
819
"""
809
820
if self ._sock is None or self ._is_connected is False :
810
821
raise MMQTTException ("MiniMQTT is not connected." )
@@ -837,6 +848,8 @@ def set_logger_level(self, log_level):
837
848
"""Sets the level of the logger, if defined during init.
838
849
839
850
:param str log_level: Level of logging to output to the REPL.
851
+ Acceptable options are ``DEBUG``, ``INFO``, ``WARNING``, or
852
+ ``ERROR``.
840
853
"""
841
854
if self .logger is None :
842
855
raise MMQTTException (
0 commit comments