Skip to content

Commit 4d003eb

Browse files
committed
allow to use any port as TLS port
fixes #140
1 parent 342b8c9 commit 4d003eb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,12 @@ def __init__(
222222

223223
self.port = MQTT_TCP_PORT
224224
if is_ssl:
225+
self._is_ssl = True
225226
self.port = MQTT_TLS_PORT
226227
if port:
227228
self.port = port
228229

229-
# define client identifer
230+
# define client identifier
230231
if client_id:
231232
# user-defined client_id MAY allow client_id's > 23 bytes or
232233
# non-alpha-numeric characters
@@ -282,12 +283,12 @@ def _get_connect_socket(self, host, port, *, timeout=1):
282283
if not isinstance(port, int):
283284
raise RuntimeError("Port must be an integer")
284285

285-
if port == MQTT_TLS_PORT and not self._ssl_context:
286+
if self._is_ssl and not self._ssl_context:
286287
raise RuntimeError(
287288
"ssl_context must be set before using adafruit_mqtt for secure MQTT."
288289
)
289290

290-
if port == MQTT_TLS_PORT:
291+
if self._is_ssl:
291292
self.logger.info(f"Establishing a SECURE SSL connection to {host}:{port}")
292293
else:
293294
self.logger.info(f"Establishing an INSECURE connection to {host}:{port}")
@@ -306,7 +307,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
306307
raise TemporaryError from exc
307308

308309
connect_host = addr_info[-1][0]
309-
if port == MQTT_TLS_PORT:
310+
if self._is_ssl:
310311
sock = self._ssl_context.wrap_socket(sock, server_hostname=host)
311312
connect_host = host
312313
sock.settimeout(timeout)

0 commit comments

Comments
 (0)