@@ -194,11 +194,12 @@ def __init__(
194
194
195
195
self .port = MQTT_TCP_PORT
196
196
if is_ssl :
197
+ self ._is_ssl = True
197
198
self .port = MQTT_TLS_PORT
198
199
if port :
199
200
self .port = port
200
201
201
- # define client identifer
202
+ # define client identifier
202
203
if client_id :
203
204
# user-defined client_id MAY allow client_id's > 23 bytes or
204
205
# non-alpha-numeric characters
@@ -254,12 +255,12 @@ def _get_connect_socket(self, host, port, *, timeout=1):
254
255
if not isinstance (port , int ):
255
256
raise RuntimeError ("Port must be an integer" )
256
257
257
- if port == MQTT_TLS_PORT and not self ._ssl_context :
258
+ if self . _is_ssl and not self ._ssl_context :
258
259
raise RuntimeError (
259
260
"ssl_context must be set before using adafruit_mqtt for secure MQTT."
260
261
)
261
262
262
- if self .logger is not None and port == MQTT_TLS_PORT :
263
+ if self .logger is not None and self . _is_ssl :
263
264
self .logger .info (f"Establishing a SECURE SSL connection to { host } :{ port } " )
264
265
elif self .logger is not None :
265
266
self .logger .info (f"Establishing an INSECURE connection to { host } :{ port } " )
@@ -280,7 +281,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
280
281
continue
281
282
282
283
connect_host = addr_info [- 1 ][0 ]
283
- if port == MQTT_TLS_PORT :
284
+ if self . _is_ssl :
284
285
sock = self ._ssl_context .wrap_socket (sock , server_hostname = host )
285
286
connect_host = host
286
287
sock .settimeout (timeout )
0 commit comments