Skip to content

Commit c55ca95

Browse files
committed
allow to use any port as TLS port
fixes adafruit#140
1 parent 729c77a commit c55ca95

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
@@ -194,11 +194,12 @@ def __init__(
194194

195195
self.port = MQTT_TCP_PORT
196196
if is_ssl:
197+
self._is_ssl = True
197198
self.port = MQTT_TLS_PORT
198199
if port:
199200
self.port = port
200201

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

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

262-
if self.logger is not None and port == MQTT_TLS_PORT:
263+
if self.logger is not None and self._is_ssl:
263264
self.logger.info(f"Establishing a SECURE SSL connection to {host}:{port}")
264265
elif self.logger is not None:
265266
self.logger.info(f"Establishing an INSECURE connection to {host}:{port}")
@@ -280,7 +281,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
280281
continue
281282

282283
connect_host = addr_info[-1][0]
283-
if port == MQTT_TLS_PORT:
284+
if self._is_ssl:
284285
sock = self._ssl_context.wrap_socket(sock, server_hostname=host)
285286
connect_host = host
286287
sock.settimeout(timeout)

0 commit comments

Comments
 (0)