Skip to content

Commit b87ca44

Browse files
author
brentru
committed
pylint a bunch
1 parent 1ffa360 commit b87ca44

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

adafruit_io/adafruit_io.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT
4040
"""
4141
import time
42-
from adafruit_io.adafruit_io_errors import AdafruitIO_RequestError, AdafruitIO_ThrottleError, AdafruitIO_MQTTError
42+
from adafruit_io.adafruit_io_errors import AdafruitIO_RequestError, AdafruitIO_ThrottleError
43+
from adafruit_io.adafruit_io_errors import AdafruitIO_MQTTError
4344

4445
__version__ = "0.0.0-auto.0"
4546
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Adafruit_IO.git"
@@ -53,9 +54,9 @@ class IO_MQTT():
5354
Client for interacting with the Adafruit IO MQTT API. The client establishes
5455
a secure connection to Adafruit IO by default.
5556
:param MiniMQTT mqtt_client: MiniMQTT Client object.
56-
:param bool secure: Enables a secure SSL/TLS connection with Adafruit IO.
5757
"""
58-
def __init__(self, mqtt_client, secure=True):
58+
# pylint: disable=protected-access
59+
def __init__(self, mqtt_client):
5960
# MiniMQTT Object
6061
mqtt_client_type = str(type(mqtt_client))
6162
if 'MQTT' in mqtt_client_type:
@@ -85,9 +86,8 @@ def connect(self):
8586
"""
8687
try:
8788
self._client.connect()
88-
except error as err:
89-
AdafruitIO_MQTTError(err)
90-
return
89+
except error as e:
90+
AdafruitIO_MQTTError(e)
9191

9292
def disconnect(self):
9393
"""Disconnects from Adafruit IO.
@@ -100,20 +100,22 @@ def is_connected(self):
100100
"""Returns if connected to Adafruit IO MQTT Broker."""
101101
return self._client.is_connected
102102

103-
def _on_connect_mqtt(self, client, userdata, flags, rc):
103+
# pylint: disable=not-callable
104+
def _on_connect_mqtt(self, client, userdata, flags, return_code):
104105
"""Runs when the on_connect callback is run from code.
105106
"""
106107
if self._logger:
107108
self._client._logger.debug('Client called on_connect.')
108-
if rc == 0:
109+
if return_code == 0:
109110
self._connected = True
110111
else:
111-
raise AdafruitIO_MQTTError(rc)
112+
raise AdafruitIO_MQTTError(return_code)
112113
# Call the user-defined on_connect callback if defined
113114
if self.on_connect is not None:
114115
self.on_connect(self)
115116

116-
def _on_disconnect_mqtt(self, client, userdata, rc):
117+
# pylint: disable=not-callable
118+
def _on_disconnect_mqtt(self, client, userdata, return_code):
117119
"""Runs when the on_disconnect callback is run from
118120
code.
119121
"""
@@ -123,7 +125,8 @@ def _on_disconnect_mqtt(self, client, userdata, rc):
123125
# Call the user-defined on_disconnect callblack if defined
124126
if self.on_disconnect is not None:
125127
self.on_disconnect(self)
126-
128+
129+
# pylint: disable=not-callable
127130
def _on_message_mqtt(self, client, topic, payload):
128131
"""Runs when the on_message callback is run from code.
129132
Parses incoming data from special Adafruit IO feeds.
@@ -140,6 +143,7 @@ def _on_message_mqtt(self, client, topic, payload):
140143
# Adafruit IO Group Feed(s)
141144
feeds = []
142145
messages = []
146+
# TODO: Remove eval here...
143147
payload = eval(payload)
144148
for feed in payload['feeds']:
145149
feeds.append(feed)
@@ -159,13 +163,13 @@ def _on_message_mqtt(self, client, topic, payload):
159163
else:
160164
raise ValueError('You must define an on_message method before calling this callback.')
161165
self.on_message(self, topic_name, message)
162-
166+
163167
def loop(self):
164168
"""Manually process messages from Adafruit IO.
165169
Use this method to check incoming subscription messages.
166170
"""
167171
self._client.loop()
168-
172+
169173
def loop_blocking(self):
170174
"""Starts a blocking loop and to processes messages
171175
from Adafruit IO. Code below this call will not run.
@@ -179,7 +183,7 @@ def subscribe(self, feed_key=None, group_key=None, shared_user=None):
179183
:param str feed_key: Adafruit IO Feed key.
180184
:param str group_key: Adafruit IO Group key.
181185
:param str shared_user: Owner of the Adafruit IO feed, required for shared feeds.
182-
186+
183187
Example of subscribing to an Adafruit IO Feed named 'temperature':
184188
185189
.. code-block:: python
@@ -220,21 +224,22 @@ def subscribe_to_randomizer(self, randomizer_id):
220224
"""
221225
self._client.subscribe('{0}/integration/words/{1}'.format(self._user, randomizer_id))
222226

223-
def subscribe_to_weather(self, integration_id, forecast_type):
227+
def subscribe_to_weather(self, weather_record, forecast):
224228
"""Subscribes to a weather forecast using the Adafruit IO PLUS weather
225229
service. This feature is only avaliable to Adafruit IO PLUS subscribers.
226-
:param int integration_id: Weather record you want data for.
227-
:param str forecast_type: Forecast data you'd like to recieve.
230+
:param int weather_record: Weather record you want data for.
231+
:param str forecast: Forecast data you'd like to recieve.
228232
"""
229-
self._client.subscribe('{0}/integration/weather/{1}/{2}'.format(self._user, integration_id, forecast_type))
233+
self._client.subscribe('{0}/integration/weather/{1}/{2}'.format(self._user,
234+
weather_record, forecast))
230235

231236
def subscribe_to_time(self, time_type):
232237
"""Adafruit IO provides some built-in MQTT topics for getting the current server time.
233238
:param str time_type: Current Adafruit IO server time. Can be `seconds`, `millis`, or `iso`.
234239
Information about these topics can be found on the Adafruit IO MQTT API Docs.:
235240
https://io.adafruit.com/api/docs/mqtt.html#time-topics
236241
"""
237-
if time_type == 'seconds' or time_type == 'millis':
242+
if 'seconds' or 'millis' in time_type:
238243
self._client.subscribe('time/'+time_type)
239244
elif time_type == 'iso':
240245
self._client.subscribe('time/ISO-8601')
@@ -247,7 +252,7 @@ def unsubscribe(self, feed_key=None, group_key=None, shared_user=None):
247252
:param str feed_key: Adafruit IO Feed key.
248253
:param str group_key: Adafruit IO Group key.
249254
:param str shared_user: Owner of the Adafruit IO feed, required for shared feeds.
250-
255+
251256
Example of unsubscribing from an Adafruit IO Feed named 'temperature':
252257
253258
.. code-block:: python
@@ -280,7 +285,7 @@ def publish_multiple(self, feeds_and_data, timeout=3, is_group=False):
280285
281286
Example of publishing multiple data points on different feeds to Adafruit IO:
282287
..code-block:: python
283-
288+
284289
client.publish_multiple([('humidity', 24.5), ('temperature', 54)])
285290
286291
"""
@@ -311,12 +316,12 @@ def publish(self, feed_key, data, shared_user=None, is_group=False):
311316
..code-block:: python
312317
313318
client.publish('temperature', 30)
314-
319+
315320
Example of publishing a floating point value to Adafruit IO on feed 'temperature'.
316321
..code-block:: python
317322
318323
client.publish('temperature', 3.14)
319-
324+
320325
Example of publishing a string to Adafruit IO on feed 'temperature'.
321326
..code-block:: python
322327
@@ -336,7 +341,7 @@ def publish(self, feed_key, data, shared_user=None, is_group=False):
336341
if is_group:
337342
self._client.publish('{0}/groups/{1}'.format(self._user, feed_key), data)
338343
return
339-
elif shared_user is not None:
344+
if shared_user is not None:
340345
self._client.publish('{0}/feeds/{1}'.format(shared_user, feed_key), data)
341346
else:
342347
self._client.publish('{0}/feeds/{1}'.format(self._user, feed_key), data)
@@ -571,5 +576,6 @@ def receive_time(self):
571576
"""
572577
path = self._compose_path('integrations/time/struct.json')
573578
time = self._get(path)
574-
return time.struct_time((time['year'], time['mon'], time['mday'], time['hour'],
575-
time['min'], time['sec'], time['wday'], time['yday'], time['isdst']))
579+
return time.struct_time((time['year'], time['mon'], time['mday'],
580+
time['hour'], time['min'], time['sec'],
581+
time['wday'], time['yday'], time['isdst']))

adafruit_io/adafruit_io_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ def __init__(self, response):
4343
class AdafruitIO_MQTTError(Exception):
4444
"""Adafruit IO MQTT error class"""
4545
def __init__(self, response):
46-
super(AdafruitIO_ThrottleError, self).__init__('Adafruit IO MQTT Error: {0}'.format(response))
46+
super(AdafruitIO_MQTTError, self).__init__('MQTT Error: {0}'.format(response))

0 commit comments

Comments
 (0)