@@ -393,12 +393,13 @@ def username_pw_set(self, username: str, password: Optional[str] = None) -> None
393393 if password is not None :
394394 self ._password = password
395395
396- def connect (
396+ def connect ( # noqa: PLR0913, too many arguments in function definition
397397 self ,
398398 clean_session : bool = True ,
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
@@ -476,19 +479,22 @@ def _send_bytes(
476479 continue
477480 raise
478481
479- def _connect ( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
482+ def _connect ( # noqa: PLR0912, PLR0913, PLR0915, Too many branches, Too many arguments , Too many statements
480483 self ,
481484 clean_session : bool = True ,
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