Skip to content

Commit e040c47

Browse files
committed
api doc's param & code-block display correctly
1 parent 4429862 commit e040c47

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ class MMQTTException(Exception):
9191

9292
def set_socket(sock, iface=None):
9393
"""Helper to set the global socket and optionally set the global network interface.
94+
9495
:param sock: socket object.
9596
:param iface: internet interface object
96-
9797
"""
9898
global _the_sock # pylint: disable=invalid-name, global-statement
9999
_the_sock = sock
@@ -105,6 +105,7 @@ def set_socket(sock, iface=None):
105105

106106
class MQTT:
107107
"""MQTT Client for CircuitPython
108+
108109
:param str broker: MQTT Broker URL or IP Address.
109110
:param int port: Optional port definition, defaults to 8883.
110111
:param str username: Username for broker authentication.
@@ -114,7 +115,6 @@ class MQTT:
114115
:param bool is_ssl: Sets a secure or insecure connection with the broker.
115116
:param bool log: Attaches a logger to the MQTT client, defaults to logging level INFO.
116117
:param int keep_alive: KeepAlive interval between the broker and the MiniMQTT client.
117-
118118
"""
119119

120120
# pylint: disable=too-many-arguments,too-many-instance-attributes, not-callable, invalid-name, no-member
@@ -201,11 +201,11 @@ def deinit(self):
201201

202202
def will_set(self, topic=None, payload=None, qos=0, retain=False):
203203
"""Sets the last will and testament properties. MUST be called before connect().
204+
204205
:param str topic: MQTT Broker topic.
205206
:param str payload: Last will disconnection payload.
206207
:param int qos: Quality of Service level.
207208
:param bool retain: Specifies if the payload is to be retained when it is published.
208-
209209
"""
210210
if self.logger is not None:
211211
self.logger.debug("Setting last will properties")
@@ -225,18 +225,18 @@ def will_set(self, topic=None, payload=None, qos=0, retain=False):
225225

226226
def add_topic_callback(self, mqtt_topic, callback_method):
227227
"""Registers a callback_method for a specific MQTT topic.
228+
228229
:param str mqtt_topic: MQTT topic.
229230
:param str callback_method: Name of callback method.
230-
231231
"""
232232
if mqtt_topic is None or callback_method is None:
233233
raise ValueError("MQTT topic and callback method must both be defined.")
234234
self._on_message_filtered[mqtt_topic] = callback_method
235235

236236
def remove_topic_callback(self, mqtt_topic):
237237
"""Removes a registered callback method.
238-
:param str mqtt_topic: MQTT topic.
239238
239+
:param str mqtt_topic: MQTT topic.
240240
"""
241241
if mqtt_topic is None:
242242
raise ValueError("MQTT Topic must be defined.")
@@ -271,8 +271,8 @@ def _handle_on_message(self, client, topic, message):
271271
# pylint: disable=too-many-branches, too-many-statements, too-many-locals
272272
def connect(self, clean_session=True):
273273
"""Initiates connection with the MQTT Broker.
274-
:param bool clean_session: Establishes a persistent session.
275274
275+
:param bool clean_session: Establishes a persistent session.
276276
"""
277277
self._sock = _the_sock.socket()
278278
self._sock.settimeout(15)
@@ -411,6 +411,7 @@ def ping(self):
411411
# pylint: disable=too-many-branches, too-many-statements
412412
def publish(self, topic, msg, retain=False, qos=0):
413413
"""Publishes a message to a topic provided.
414+
414415
:param str topic: Unique topic identifier.
415416
:param str msg: Data to send to the broker.
416417
:param int msg: Data to send to the broker.
@@ -419,16 +420,19 @@ def publish(self, topic, msg, retain=False, qos=0):
419420
:param int qos: Quality of Service level for the message.
420421
421422
Example of sending an integer, 3, to the broker on topic 'piVal'.
423+
422424
.. code-block:: python
423425
424426
mqtt_client.publish('topics/piVal', 3)
425427
426428
Example of sending a float, 3.14, to the broker on topic 'piVal'.
429+
427430
.. code-block:: python
428431
429432
mqtt_client.publish('topics/piVal', 3.14)
430433
431434
Example of sending a string, 'threepointonefour', to the broker on topic piVal.
435+
432436
.. code-block:: python
433437
434438
mqtt_client.publish('topics/piVal', 'threepointonefour')
@@ -509,27 +513,32 @@ def publish(self, topic, msg, retain=False, qos=0):
509513
def subscribe(self, topic, qos=0):
510514
"""Subscribes to a topic on the MQTT Broker.
511515
This method can subscribe to one topics or multiple topics.
516+
512517
:param str topic: Unique MQTT topic identifier.
513518
:param int qos: Quality of Service level for the topic, defaults to zero.
514519
:param tuple topic: Tuple containing topic identifier strings and qos level integers.
515520
:param list topic: List of tuples containing topic identifier strings and qos.
516521
517522
Example of subscribing a topic string.
523+
518524
.. code-block:: python
519525
520526
mqtt_client.subscribe('topics/ledState')
521527
522528
Example of subscribing to a topic and setting the qos level to 1.
529+
523530
.. code-block:: python
524531
525532
mqtt_client.subscribe('topics/ledState', 1)
526533
527534
Example of subscribing to topic string and setting qos level to 1, as a tuple.
535+
528536
.. code-block:: python
529537
530538
mqtt_client.subscribe(('topics/ledState', 1))
531539
532540
Example of subscribing to multiple topics with different qos levels.
541+
533542
.. code-block:: python
534543
535544
mqtt_client.subscribe([('topics/ledState', 1), ('topics/servoAngle', 0)])
@@ -583,15 +592,18 @@ def subscribe(self, topic, qos=0):
583592

584593
def unsubscribe(self, topic):
585594
"""Unsubscribes from a MQTT topic.
595+
586596
:param str topic: Unique MQTT topic identifier.
587597
:param list topic: List of tuples containing topic identifier strings.
588598
589599
Example of unsubscribing from a topic string.
600+
590601
.. code-block:: python
591602
592603
mqtt_client.unsubscribe('topics/ledState')
593604
594605
Example of unsubscribing from multiple topics.
606+
595607
.. code-block:: python
596608
597609
mqtt_client.unsubscribe([('topics/ledState'), ('topics/servoAngle')])
@@ -645,6 +657,7 @@ def unsubscribe(self, topic):
645657

646658
def reconnect(self, resub_topics=True):
647659
"""Attempts to reconnect to the MQTT broker.
660+
648661
:param bool resub_topics: Resubscribe to previously subscribed topics.
649662
"""
650663
if self.logger is not None:
@@ -672,7 +685,6 @@ def loop_forever(self):
672685
next major release. Please see examples/minimqtt_pub_sub_blocking.py
673686
for an example of creating a blocking loop which can handle wireless
674687
network events.
675-
676688
"""
677689
while True:
678690
if self._sock.connected:
@@ -681,7 +693,6 @@ def loop_forever(self):
681693
def loop(self):
682694
"""Non-blocking message loop. Use this method to
683695
check incoming subscription messages.
684-
685696
"""
686697
if self._timestamp == 0:
687698
self._timestamp = time.monotonic()
@@ -744,6 +755,7 @@ def _recv_len(self):
744755

745756
def _send_str(self, string):
746757
"""Packs and encodes a string to a socket.
758+
747759
:param str string: String to write to the socket.
748760
"""
749761
self._sock.send(struct.pack("!H", len(string)))
@@ -755,6 +767,7 @@ def _send_str(self, string):
755767
@staticmethod
756768
def _check_topic(topic):
757769
"""Checks if topic provided is a valid mqtt topic.
770+
758771
:param str topic: Topic identifier
759772
"""
760773
if topic is None:
@@ -769,6 +782,7 @@ def _check_topic(topic):
769782
@staticmethod
770783
def _check_qos(qos_level):
771784
"""Validates the quality of service level.
785+
772786
:param int qos_level: Desired QoS level.
773787
"""
774788
if isinstance(qos_level, int):
@@ -803,6 +817,7 @@ def mqtt_msg(self):
803817
@mqtt_msg.setter
804818
def mqtt_msg(self, msg_size):
805819
"""Sets the maximum MQTT message payload size.
820+
806821
:param int msg_size: Maximum MQTT payload size.
807822
"""
808823
if msg_size < MQTT_MSG_MAX_SZ:
@@ -811,13 +826,15 @@ def mqtt_msg(self, msg_size):
811826
### Logging ###
812827
def attach_logger(self, logger_name="log"):
813828
"""Initializes and attaches a logger to the MQTTClient.
829+
814830
:param str logger_name: Name of the logger instance
815831
"""
816832
self.logger = logging.getLogger(logger_name)
817833
self.logger.setLevel(logging.INFO)
818834

819835
def set_logger_level(self, log_level):
820836
"""Sets the level of the logger, if defined during init.
837+
821838
:param string log_level: Level of logging to output to the REPL.
822839
"""
823840
if self.logger is None:

0 commit comments

Comments
 (0)