|
81 | 81 | _the_interface = None # pylint: disable=invalid-name |
82 | 82 | _the_sock = None # pylint: disable=invalid-name |
83 | 83 |
|
84 | | - |
85 | 84 | class MMQTTException(Exception): |
86 | 85 | """MiniMQTT Exception class.""" |
87 | 86 |
|
88 | 87 | # pylint: disable=unnecessary-pass |
89 | 88 | # pass |
90 | 89 |
|
91 | | - |
92 | 90 | # Legacy ESP32SPI Socket API |
93 | 91 | def set_socket(sock, iface=None): |
94 | 92 | """Legacy API for setting the socket and network interface, use a `Session` instead. |
@@ -572,33 +570,13 @@ def ping(self): |
572 | 570 | # pylint: disable=too-many-branches, too-many-statements |
573 | 571 | def publish(self, topic, msg, retain=False, qos=0): |
574 | 572 | """Publishes a message to a topic provided. |
575 | | -
|
576 | 573 | :param str topic: Unique topic identifier. |
577 | 574 | :param str,int,float msg: Data to send to the broker. |
578 | 575 | :param bool retain: Whether the message is saved by the broker. |
579 | 576 | :param int qos: Quality of Service level for the message, defaults to |
580 | 577 | zero. Conventional options are ``0`` (send at most once), ``1`` |
581 | 578 | (send at least once), or ``2`` (send exactly once). |
582 | 579 |
|
583 | | - .. note:: Only options ``1`` or ``0`` are QoS levels supported by this library. |
584 | | -
|
585 | | - Example of sending an integer, 3, to the broker on topic 'piVal'. |
586 | | -
|
587 | | - .. code-block:: python |
588 | | -
|
589 | | - mqtt_client.publish('topics/piVal', 3) |
590 | | -
|
591 | | - Example of sending a float, 3.14, to the broker on topic 'piVal'. |
592 | | -
|
593 | | - .. code-block:: python |
594 | | -
|
595 | | - mqtt_client.publish('topics/piVal', 3.14) |
596 | | -
|
597 | | - Example of sending a string, 'threepointonefour', to the broker on topic piVal. |
598 | | -
|
599 | | - .. code-block:: python |
600 | | -
|
601 | | - mqtt_client.publish('topics/piVal', 'threepointonefour') |
602 | 580 | """ |
603 | 581 | self.is_connected() |
604 | 582 | self._valid_topic(topic) |
@@ -687,30 +665,6 @@ def subscribe(self, topic, qos=0): |
687 | 665 |
|
688 | 666 | .. note:: Only options ``1`` or ``0`` are QoS levels supported by this library. |
689 | 667 |
|
690 | | - Example of subscribing a topic string. |
691 | | -
|
692 | | - .. code-block:: python |
693 | | -
|
694 | | - mqtt_client.subscribe('topics/ledState') |
695 | | -
|
696 | | - Example of subscribing to a topic and setting the qos level to 1. |
697 | | -
|
698 | | - .. code-block:: python |
699 | | -
|
700 | | - mqtt_client.subscribe('topics/ledState', 1) |
701 | | -
|
702 | | - Example of subscribing to topic string and setting qos level to 1, as a tuple. |
703 | | -
|
704 | | - .. code-block:: python |
705 | | -
|
706 | | - mqtt_client.subscribe(('topics/ledState', 1)) |
707 | | -
|
708 | | - Example of subscribing to multiple topics with different qos levels. |
709 | | -
|
710 | | - .. code-block:: python |
711 | | -
|
712 | | - mqtt_client.subscribe([('topics/ledState', 1), ('topics/servoAngle', 0)]) |
713 | | -
|
714 | 668 | """ |
715 | 669 | self.is_connected() |
716 | 670 | topics = None |
@@ -882,7 +836,7 @@ def _wait_for_msg(self, timeout=0.1): |
882 | 836 | if error.errno == errno.ETIMEDOUT: |
883 | 837 | # raised by a socket timeout in socketpool |
884 | 838 | return None |
885 | | - raise MMQTTException(error) |
| 839 | + raise MMQTTException from error |
886 | 840 |
|
887 | 841 | # Block while we parse the rest of the response |
888 | 842 | self._sock.settimeout(timeout) |
|
0 commit comments