Skip to content

Commit

Permalink
Merge pull request #226 from vladak/connect_session_id
Browse files Browse the repository at this point in the history
allow to specify session_id for connect()
  • Loading branch information
dhalbert authored Jan 2, 2025
2 parents e834919 + dfaf68e commit b47a501
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions adafruit_minimqtt/adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,13 @@ def username_pw_set(self, username: str, password: Optional[str] = None) -> None
if password is not None:
self._password = password

def connect(
def connect( # noqa: PLR0913, too many arguments in function definition
self,
clean_session: bool = True,
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 @@ -476,19 +479,22 @@ def _send_bytes(
continue
raise

def _connect( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
def _connect( # noqa: PLR0912, PLR0913, PLR0915, Too many branches, Too many arguments, Too many statements
self,
clean_session: bool = True,
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 b47a501

Please sign in to comment.