Skip to content

Commit e0c783d

Browse files
committed
allow to specify session_id for connect()
1 parent e834919 commit e0c783d

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
@@ -482,13 +485,16 @@ def _connect( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
482485
host: Optional[str] = None,
483486
port: Optional[int] = None,
484487
keep_alive: Optional[int] = None,
488+
session_id: Optional[str] = None,
485489
) -> int:
486490
"""Initiates connection with the MQTT Broker.
487491
488492
:param bool clean_session: Establishes a persistent session.
489493
:param str host: Hostname or IP address of the remote broker.
490494
:param int port: Network port of the remote broker.
491495
:param int keep_alive: Maximum period allowed for communication, in seconds.
496+
:param str session_id: unique session ID,
497+
used for multiple simultaneous connections to the same host
492498
493499
"""
494500
if host:
@@ -511,6 +517,7 @@ def _connect( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
511517
self.broker,
512518
self.port,
513519
proto="mqtt:",
520+
session_id=session_id,
514521
timeout=self._socket_timeout,
515522
is_ssl=self._is_ssl,
516523
ssl_context=self._ssl_context,

0 commit comments

Comments
 (0)