Skip to content

Commit

Permalink
allow to specify session_id for connect()
Browse files Browse the repository at this point in the history
  • Loading branch information
vladak committed Jan 2, 2025
1 parent e834919 commit e0c783d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion adafruit_minimqtt/adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def connect(
host: Optional[str] = None,
port: Optional[int] = None,
keep_alive: Optional[int] = None,
session_id: Optional[str] = None,
) -> int:
"""Initiates connection with the MQTT Broker. Will perform exponential back-off
on connect failures.
Expand All @@ -408,7 +409,8 @@ def connect(
:param int port: Network port of the remote broker.
:param int keep_alive: Maximum period allowed for communication
within single connection attempt, in seconds.
:param str session_id: unique session ID,
used for multiple simultaneous connections to the same host
"""

last_exception = None
Expand All @@ -430,6 +432,7 @@ def connect(
host=host,
port=port,
keep_alive=keep_alive,
session_id=session_id
)
self._reset_reconnect_backoff()
return ret
Expand Down Expand Up @@ -482,13 +485,16 @@ def _connect( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
host: Optional[str] = None,
port: Optional[int] = None,
keep_alive: Optional[int] = None,
session_id: Optional[str] = None,
) -> int:
"""Initiates connection with the MQTT Broker.
:param bool clean_session: Establishes a persistent session.
:param str host: Hostname or IP address of the remote broker.
:param int port: Network port of the remote broker.
:param int keep_alive: Maximum period allowed for communication, in seconds.
:param str session_id: unique session ID,
used for multiple simultaneous connections to the same host
"""
if host:
Expand All @@ -511,6 +517,7 @@ def _connect( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
self.broker,
self.port,
proto="mqtt:",
session_id=session_id,
timeout=self._socket_timeout,
is_ssl=self._is_ssl,
ssl_context=self._ssl_context,
Expand Down

0 comments on commit e0c783d

Please sign in to comment.