Skip to content

Commit 15b8789

Browse files
authored
Allow user to override keepalive on connect
The `keepalive` is always set to `KEEP_ALIVE_SEC` and cannot be overridden by the user. This fix uses the user-provided `keepalive` from `kwargs` and defaults to `KEEP_ALIVE_SEC` if there is None. This fixes #28
1 parent 4d092e7 commit 15b8789

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Adafruit_IO/mqtt_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ def connect(self, **kwargs):
102102
# Skip calling connect if already connected.
103103
if self._connected:
104104
return
105+
# If given, use user-provided keepalive, otherwise default to KEEP_ALIVE_SEC
106+
keepalive = kwargs.pop('keepalive', KEEP_ALIVE_SEC)
105107
# Connect to the Adafruit IO MQTT service.
106108
self._client.connect(self._service_host, port=self._service_port,
107-
keepalive=KEEP_ALIVE_SEC, **kwargs)
109+
keepalive=keepalive, **kwargs)
108110

109111
def is_connected(self):
110112
"""Returns True if connected to Adafruit.IO and False if not connected.

0 commit comments

Comments
 (0)