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