Skip to content

Commit 3f934e3

Browse files
author
brentru
committed
update to remove private minimqtt properties
1 parent 6d25933 commit 3f934e3

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

adafruit_gc_iot_core.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class MQTT_API:
5757
5858
"""
5959

60-
# pylint: disable=protected-access
6160
def __init__(self, mqtt_client):
6261
# Check that provided object is a MiniMQTT client object
6362
mqtt_client_type = str(type(mqtt_client))
@@ -69,19 +68,19 @@ def __init__(self, mqtt_client):
6968
)
7069
# Verify that the MiniMQTT client was setup correctly.
7170
try:
72-
self._user = self._client._user
71+
self.user = self._client.user
7372
except:
7473
raise TypeError("Google Cloud Core IoT MQTT API requires a username.")
7574
# Validate provided JWT before connecting
7675
try:
77-
JWT.validate(self._client._pass)
76+
JWT.validate(self._client.password)
7877
except:
7978
raise TypeError("Invalid JWT provided.")
8079
# If client has KeepAlive =0 or if KeepAlive > 20min,
8180
# set KeepAlive to 19 minutes to avoid disconnection
8281
# due to Idle Time (https://cloud.google.com/iot/quotas).
83-
if self._client._keep_alive == 0 or self._client._keep_alive >= 1200:
84-
self._client._keep_alive = 1140
82+
if self._client.keep_alive == 0 or self._client.keep_alive >= 1200:
83+
self._client.keep_alive = 1140
8584
# User-defined MQTT callback methods must be init'd to None
8685
self.on_connect = None
8786
self.on_disconnect = None
@@ -94,14 +93,14 @@ def __init__(self, mqtt_client):
9493
self._client.on_message = self._on_message_mqtt
9594
self._client.on_subscribe = self._on_subscribe_mqtt
9695
self._client.on_unsubscribe = self._on_unsubscribe_mqtt
97-
self._logger = False
98-
if self._client._logger is not None:
96+
self.logger = False
97+
if self._client.logger is not None:
9998
# Allow MQTT_API to utilize MiniMQTT Client's logger
100-
self._logger = True
99+
self.logger = True
101100
self._client.set_logger_level("DEBUG")
102101
self._connected = False
103102
# Set up a device identifier by splitting out the full CID
104-
self.device_id = self._client._client_id.split("/")[7]
103+
self.device_id = self._client.client_id.split("/")[7]
105104

106105
def __enter__(self):
107106
return self
@@ -142,8 +141,8 @@ def is_connected(self):
142141
def _on_connect_mqtt(self, client, userdata, flags, return_code):
143142
"""Runs when the mqtt client calls on_connect.
144143
"""
145-
if self._logger:
146-
self._client._logger.debug("Client called on_connect.")
144+
if self.logger:
145+
self._client.logger.debug("Client called on_connect.")
147146
if return_code == 0:
148147
self._connected = True
149148
else:
@@ -156,8 +155,8 @@ def _on_connect_mqtt(self, client, userdata, flags, return_code):
156155
def _on_disconnect_mqtt(self, client, userdata, return_code):
157156
"""Runs when the client calls on_disconnect.
158157
"""
159-
if self._logger:
160-
self._client._logger.debug("Client called on_disconnect")
158+
if self.logger:
159+
self._client.logger.debug("Client called on_disconnect")
161160
self._connected = False
162161
# Call the user-defined on_disconnect callblack if defined
163162
if self.on_disconnect is not None:
@@ -167,26 +166,26 @@ def _on_disconnect_mqtt(self, client, userdata, return_code):
167166
def _on_message_mqtt(self, client, topic, payload):
168167
"""Runs when the client calls on_message.
169168
"""
170-
if self._logger:
171-
self._client._logger.debug("Client called on_message")
169+
if self.logger:
170+
self._client.logger.debug("Client called on_message")
172171
if self.on_message is not None:
173172
self.on_message(self, topic, payload)
174173

175174
# pylint: disable=not-callable
176175
def _on_subscribe_mqtt(self, client, user_data, topic, qos):
177176
"""Runs when the client calls on_subscribe.
178177
"""
179-
if self._logger:
180-
self._client._logger.debug("Client called on_subscribe")
178+
if self.logger:
179+
self._client.logger.debug("Client called on_subscribe")
181180
if self.on_subscribe is not None:
182181
self.on_subscribe(self, user_data, topic, qos)
183182

184183
# pylint: disable=not-callable
185184
def _on_unsubscribe_mqtt(self, client, user_data, topic, pid):
186185
"""Runs when the client calls on_unsubscribe.
187186
"""
188-
if self._logger:
189-
self._client._logger.debug("Client called on_unsubscribe")
187+
if self.logger:
188+
self._client.logger.debug("Client called on_unsubscribe")
190189
if self.on_unsubscribe is not None:
191190
self.on_unsubscribe(self, user_data, topic, pid)
192191

@@ -319,10 +318,10 @@ def __init__(self, esp, secrets, log=False):
319318
raise AttributeError(
320319
"Project settings are kept in secrets.py, please add them there!"
321320
)
322-
self._logger = None
321+
self.logger = None
323322
if log is True:
324-
self._logger = logging.getLogger("log")
325-
self._logger.setLevel(logging.DEBUG)
323+
self.logger = logging.getLogger("log")
324+
self.logger.setLevel(logging.DEBUG)
326325
# Configuration, from secrets file
327326
self._proj_id = secrets["project_id"]
328327
self._region = secrets["cloud_region"]
@@ -340,8 +339,8 @@ def client_id(self):
340339
client_id = "projects/{0}/locations/{1}/registries/{2}/devices/{3}".format(
341340
self._proj_id, self._region, self._reg_id, self._device_id
342341
)
343-
if self._logger:
344-
self._logger.debug("Client ID: {}".format(client_id))
342+
if self.logger:
343+
self.logger.debug("Client ID: {}".format(client_id))
345344
return client_id
346345

347346

@@ -357,8 +356,8 @@ def generate_jwt(self, ttl=43200, algo="RS256"):
357356
print("Generated JWT: ", jwt)
358357
359358
"""
360-
if self._logger:
361-
self._logger.debug("Generating JWT...")
359+
if self.logger:
360+
self.logger.debug("Generating JWT...")
362361
ntp = NTP.NTP(self._esp)
363362
ntp.set_time()
364363
claims = {

0 commit comments

Comments
 (0)