Skip to content

Commit

Permalink
Bump paho-mqtt from 2.0.0 to 2.1.0 (#2316)
Browse files Browse the repository at this point in the history
* Bump paho-mqtt from 2.0.0 to 2.1.0

Bumps [paho-mqtt](https://github.com/eclipse/paho.mqtt.python) from 2.0.0 to 2.1.0.
- [Release notes](https://github.com/eclipse/paho.mqtt.python/releases)
- [Changelog](https://github.com/eclipse/paho.mqtt.python/blob/master/ChangeLog.txt)
- [Commits](eclipse/paho.mqtt.python@v2.0.0...v2.1.0)

---
updated-dependencies:
- dependency-name: paho-mqtt
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update paho-mqtt==2.1.0

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>

[skip ci]
  • Loading branch information
dependabot[bot] committed May 10, 2024
1 parent dab4624 commit 5e90f3b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/paho/mqtt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.0.0"
__version__ = "2.1.0"


class MQTTException(Exception):
Expand Down
59 changes: 38 additions & 21 deletions lib/paho/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class WebsocketConnectionError(ConnectionError):
pass


def error_string(mqtt_errno: MQTTErrorCode) -> str:
def error_string(mqtt_errno: MQTTErrorCode | int) -> str:
"""Return the error string associated with an mqtt error number."""
if mqtt_errno == MQTT_ERR_SUCCESS:
return "No error."
Expand Down Expand Up @@ -465,7 +465,7 @@ def _force_bytes(s: str | bytes) -> bytes:
return s


def _encode_payload(payload: str | bytes | bytearray | int | float | None) -> bytes:
def _encode_payload(payload: str | bytes | bytearray | int | float | None) -> bytes|bytearray:
if isinstance(payload, str):
return payload.encode("utf-8")

Expand Down Expand Up @@ -648,7 +648,7 @@ class Client:
:param CallbackAPIVersion callback_api_version: define the API version for user-callback (on_connect, on_publish,...).
This field is required and it's recommended to use the latest version (CallbackAPIVersion.API_VERSION2).
See each callback for description of API for each version. The file migrations.md contains details on
See each callback for description of API for each version. The file docs/migrations.rst contains details on
how to migrate between version.
:param str client_id: the unique client id string used when connecting to the
Expand Down Expand Up @@ -682,6 +682,10 @@ class Client:
:param transport: use "websockets" to use WebSockets as the transport
mechanism. Set to "tcp" to use raw TCP, which is the default.
Use "unix" to use Unix sockets as the transport mechanism; note that
this option is only available on platforms that support Unix sockets,
and the "host" argument is interpreted as the path to the Unix socket
file in this case.
:param bool manual_ack: normally, when a message is received, the library automatically
acknowledges after on_message callback returns. manual_ack=True allows the application to
Expand Down Expand Up @@ -728,19 +732,21 @@ def on_connect(client, userdata, flags, reason_code, properties):

def __init__(
self,
callback_api_version: CallbackAPIVersion,
client_id: str = "",
callback_api_version: CallbackAPIVersion = CallbackAPIVersion.VERSION1,
client_id: str | None = "",
clean_session: bool | None = None,
userdata: Any = None,
protocol: int = MQTTv311,
transport: Literal["tcp", "websockets"] = "tcp",
protocol: MQTTProtocolVersion = MQTTv311,
transport: Literal["tcp", "websockets", "unix"] = "tcp",
reconnect_on_failure: bool = True,
manual_ack: bool = False,
) -> None:
transport = transport.lower() # type: ignore
if transport not in ("websockets", "tcp"):
if transport == "unix" and not hasattr(socket, "AF_UNIX"):
raise ValueError('"unix" transport not supported')
elif transport not in ("websockets", "tcp", "unix"):
raise ValueError(
f'transport must be "websockets" or "tcp", not {transport}')
f'transport must be "websockets", "tcp" or "unix", not {transport}')

self._manual_ack = manual_ack
self._transport = transport
Expand All @@ -764,7 +770,7 @@ def __init__(
# Help user to migrate, it probably provided a client id
# as first arguments
raise ValueError(
"Unsupported callback API version: version 2.0 added a callback_api_version, see migrations.md for details"
"Unsupported callback API version: version 2.0 added a callback_api_version, see docs/migrations.rst for details"
)
if self._callback_api_version not in CallbackAPIVersion:
raise ValueError("Unsupported callback API version")
Expand Down Expand Up @@ -931,7 +937,7 @@ def keepalive(self, value: int) -> None:
self._keepalive = value

@property
def transport(self) -> Literal["tcp", "websockets"]:
def transport(self) -> Literal["tcp", "websockets", "unix"]:
"""
Transport method used for the connection ("tcp" or "websockets").
Expand All @@ -953,7 +959,7 @@ def protocol(self) -> MQTTProtocolVersion:
This property is read-only.
"""
return self.protocol
return self._protocol

@property
def connect_timeout(self) -> float:
Expand Down Expand Up @@ -2032,7 +2038,7 @@ def subscribe(
return self._send_subscribe(False, topic_qos_list, properties)

def unsubscribe(
self, topic: str, properties: Properties | None = None
self, topic: str | list[str], properties: Properties | None = None
) -> tuple[MQTTErrorCode, int | None]:
"""Unsubscribe the client from one or more topics.
Expand Down Expand Up @@ -2356,7 +2362,6 @@ def loop_stop(self) -> MQTTErrorCode:
self._thread_terminate = True
if threading.current_thread() != self._thread:
self._thread.join()
self._thread = None

return MQTTErrorCode.MQTT_ERR_SUCCESS

Expand Down Expand Up @@ -2445,7 +2450,7 @@ def on_connect(self) -> CallbackOnConnect | None:
connect_callback(client, userdata, flags, rc)
* For MQTT it's v5.0::
* For MQTT v5.0 it's::
connect_callback(client, userdata, flags, reason_code, properties)
Expand Down Expand Up @@ -2732,7 +2737,7 @@ def on_disconnect(self) -> CallbackOnDisconnect | None:
disconnect_callback(client, userdata, rc)
* For MQTT it's v5.0::
* For MQTT v5.0 it's::
disconnect_callback(client, userdata, reason_code, properties)
Expand Down Expand Up @@ -3363,7 +3368,7 @@ def _send_publish(
self,
mid: int,
topic: bytes,
payload: bytes = b"",
payload: bytes|bytearray = b"",
qos: int = 0,
retain: bool = False,
dup: bool = False,
Expand All @@ -3373,7 +3378,7 @@ def _send_publish(
# we assume that topic and payload are already properly encoded
if not isinstance(topic, bytes):
raise TypeError('topic must be bytes, not str')
if payload and not isinstance(payload, bytes):
if payload and not isinstance(payload, (bytes, bytearray)):
raise TypeError('payload must be bytes if set')

if self._sock is None:
Expand Down Expand Up @@ -3462,7 +3467,7 @@ def _send_simple_command(self, command: int) -> MQTTErrorCode:
return self._packet_queue(command, packet, 0, 0)

def _send_connect(self, keepalive: int) -> MQTTErrorCode:
proto_ver = self._protocol
proto_ver = int(self._protocol)
# hard-coded UTF-8 encoded string
protocol = b"MQTT" if proto_ver >= MQTTv311 else b"MQIsdp"

Expand Down Expand Up @@ -4514,7 +4519,10 @@ def _handle_on_connect_fail(self) -> None:
MQTT_LOG_ERR, 'Caught exception in on_connect_fail: %s', err)

def _thread_main(self) -> None:
self.loop_forever(retry_first_connection=True)
try:
self.loop_forever(retry_first_connection=True)
finally:
self._thread = None

def _reconnect_wait(self) -> None:
# See reconnect_delay_set for details
Expand Down Expand Up @@ -4595,7 +4603,11 @@ def _get_proxy(self) -> dict[str, Any] | None:
return None

def _create_socket(self) -> SocketLike:
sock = self._create_socket_connection()
if self._transport == "unix":
sock = self._create_unix_socket_connection()
else:
sock = self._create_socket_connection()

if self._ssl:
sock = self._ssl_wrap_socket(sock)

Expand All @@ -4612,6 +4624,11 @@ def _create_socket(self) -> SocketLike:

return sock

def _create_unix_socket_connection(self) -> _socket.socket:
unix_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
unix_socket.connect(self._host)
return unix_socket

def _create_socket_connection(self) -> _socket.socket:
proxy = self._get_proxy()
addr = (self._host, self._port)
Expand Down
6 changes: 3 additions & 3 deletions lib/paho/mqtt/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from collections.abc import Iterable
from typing import TYPE_CHECKING, Any, List, Tuple, Union

from paho.mqtt.enums import CallbackAPIVersion
from paho.mqtt.enums import CallbackAPIVersion, MQTTProtocolVersion
from paho.mqtt.properties import Properties
from paho.mqtt.reasoncodes import ReasonCode

Expand Down Expand Up @@ -112,7 +112,7 @@ def multiple(
will: MessageDict | None = None,
auth: AuthParameter | None = None,
tls: TLSParameter | None = None,
protocol: int = paho.MQTTv311,
protocol: MQTTProtocolVersion = paho.MQTTv311,
transport: Literal["tcp", "websockets"] = "tcp",
proxy_args: Any | None = None,
) -> None:
Expand Down Expand Up @@ -240,7 +240,7 @@ def single(
will: MessageDict | None = None,
auth: AuthParameter | None = None,
tls: TLSParameter | None = None,
protocol: int = paho.MQTTv311,
protocol: MQTTProtocolVersion = paho.MQTTv311,
transport: Literal["tcp", "websockets"] = "tcp",
proxy_args: Any | None = None,
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion lib/paho/mqtt/reasoncodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ReasonCode:
"""

def __init__(self, packetType, aName="Success", identifier=-1):
def __init__(self, packetType: int, aName: str ="Success", identifier: int =-1):
"""
packetType: the type of the packet, such as PacketTypes.CONNECT that
this reason code will be used with. Some reason codes have different
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Mako==1.3.3
MarkupSafe==2.1.5
musicbrainzngs==0.7.1
packaging==24.0
paho-mqtt==2.0.0
paho-mqtt==2.1.0
platformdirs==4.2.1
plexapi==4.15.12
portend==3.2.0
Expand Down

0 comments on commit 5e90f3b

Please sign in to comment.