Skip to content

Commit c3f5eb3

Browse files
committed
allow to specify session_id for connect()
1 parent 62abc1a commit c3f5eb3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ def connect(
399399
host: Optional[str] = None,
400400
port: Optional[int] = None,
401401
keep_alive: Optional[int] = None,
402+
session_id: Optional[str] = None,
402403
) -> int:
403404
"""Initiates connection with the MQTT Broker. Will perform exponential back-off
404405
on connect failures.
@@ -408,7 +409,8 @@ def connect(
408409
:param int port: Network port of the remote broker.
409410
:param int keep_alive: Maximum period allowed for communication
410411
within single connection attempt, in seconds.
411-
412+
:param str session_id: unique session ID,
413+
used for multiple simultaneous connections to the same host
412414
"""
413415

414416
last_exception = None
@@ -430,6 +432,7 @@ def connect(
430432
host=host,
431433
port=port,
432434
keep_alive=keep_alive,
435+
session_id=session_id
433436
)
434437
self._reset_reconnect_backoff()
435438
return ret
@@ -467,13 +470,16 @@ def _connect( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
467470
host: Optional[str] = None,
468471
port: Optional[int] = None,
469472
keep_alive: Optional[int] = None,
473+
session_id: Optional[str] = None,
470474
) -> int:
471475
"""Initiates connection with the MQTT Broker.
472476
473477
:param bool clean_session: Establishes a persistent session.
474478
:param str host: Hostname or IP address of the remote broker.
475479
:param int port: Network port of the remote broker.
476480
:param int keep_alive: Maximum period allowed for communication, in seconds.
481+
:param str session_id: unique session ID,
482+
used for multiple simultaneous connections to the same host
477483
478484
"""
479485
if host:
@@ -496,6 +502,7 @@ def _connect( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
496502
self.broker,
497503
self.port,
498504
proto="mqtt:",
505+
session_id=session_id,
499506
timeout=self._socket_timeout,
500507
is_ssl=self._is_ssl,
501508
ssl_context=self._ssl_context,

0 commit comments

Comments
 (0)