Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to specify session_id for connect() #226

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading