Skip to content

Commit 4e99a25

Browse files
committed
allow to use any port as TLS port
fixes adafruit#140
1 parent 645ae31 commit 4e99a25

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,12 @@ def __init__(
195195

196196
self.port = MQTT_TCP_PORT
197197
if is_ssl:
198+
self._is_ssl = True
198199
self.port = MQTT_TLS_PORT
199200
if port:
200201
self.port = port
201202

202-
# define client identifer
203+
# define client identifier
203204
if client_id:
204205
# user-defined client_id MAY allow client_id's > 23 bytes or
205206
# non-alpha-numeric characters
@@ -255,15 +256,13 @@ def _get_connect_socket(self, host, port, *, timeout=1):
255256
if not isinstance(port, int):
256257
raise RuntimeError("Port must be an integer")
257258

258-
if port == MQTT_TLS_PORT and not self._ssl_context:
259+
if self._is_ssl and not self._ssl_context:
259260
raise RuntimeError(
260261
"ssl_context must be set before using adafruit_mqtt for secure MQTT."
261262
)
262263

263-
if self.logger is not None and port == MQTT_TLS_PORT:
264-
self.logger.info(
265-
"Establishing a SECURE SSL connection to {0}:{1}".format(host, port)
266-
)
264+
if self.logger is not None and self._is_ssl:
265+
self.logger.info(f"Establishing a SECURE SSL connection to {host}:{port}")
267266
elif self.logger is not None:
268267
self.logger.info(
269268
"Establishing an INSECURE connection to {0}:{1}".format(host, port)
@@ -285,7 +284,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
285284
continue
286285

287286
connect_host = addr_info[-1][0]
288-
if port == MQTT_TLS_PORT:
287+
if self._is_ssl:
289288
sock = self._ssl_context.wrap_socket(sock, server_hostname=host)
290289
connect_host = host
291290
sock.settimeout(timeout)

0 commit comments

Comments
 (0)