35
35
* Adafruit CircuitPython firmware for the supported boards:
36
36
https://github.com/adafruit/circuitpython/releases
37
37
"""
38
- from time import struct_time
38
+ import time
39
39
from adafruit_io .adafruit_io_errors import (
40
40
AdafruitIO_RequestError ,
41
41
AdafruitIO_ThrottleError ,
@@ -95,8 +95,8 @@ def connect(self):
95
95
"""
96
96
try :
97
97
self ._client .connect ()
98
- except error as e :
99
- AdafruitIO_MQTTError (e )
98
+ except :
99
+ raise AdafruitIO_MQTTError ("Unable to connect to Adafruit IO." )
100
100
101
101
def disconnect (self ):
102
102
"""Disconnects from Adafruit IO.
@@ -109,7 +109,7 @@ def is_connected(self):
109
109
"""Returns if connected to Adafruit IO MQTT Broker."""
110
110
return self ._client .is_connected
111
111
112
- # pylint: disable=not-callable
112
+ # pylint: disable=not-callable, unused-argument
113
113
def _on_connect_mqtt (self , client , userdata , flags , return_code ):
114
114
"""Runs when the on_connect callback is run from code.
115
115
"""
@@ -123,7 +123,7 @@ def _on_connect_mqtt(self, client, userdata, flags, return_code):
123
123
if self .on_connect is not None :
124
124
self .on_connect (self )
125
125
126
- # pylint: disable=not-callable
126
+ # pylint: disable=not-callable, unused-argument
127
127
def _on_disconnect_mqtt (self , client , userdata , return_code ):
128
128
"""Runs when the on_disconnect callback is run from
129
129
code.
@@ -307,18 +307,19 @@ def publish_multiple(self, feeds_and_data, timeout=3, is_group=False):
307
307
"""
308
308
if isinstance (feeds_and_data , list ):
309
309
feed_data = []
310
- for t , d in feeds_and_data :
311
- feed_data .append ((t , d ))
310
+ for topic , data in feeds_and_data :
311
+ feed_data .append ((topic , data ))
312
312
else :
313
313
raise AdafruitIO_MQTTError ("This method accepts a list of tuples." )
314
- for t , d in feed_data :
314
+ for topic , data in feed_data :
315
315
if is_group :
316
- self .publish (t , d , is_group = True )
316
+ self .publish (topic , data , is_group = True )
317
317
else :
318
- self .publish (t , d )
318
+ self .publish (topic , data )
319
319
time .sleep (timeout )
320
320
321
- def publish (self , feed_key , data , metadata = None , shared_user = None , is_group = False ):
321
+ # pylint: disable=too-many-arguments
322
+ def publish (self , feed_key , data , metadata = None , shared_user = None , is_group = False ):
322
323
"""Publishes to an An Adafruit IO Feed.
323
324
:param str feed_key: Adafruit IO Feed key.
324
325
:param str data: Data to publish to the feed or group.
@@ -343,7 +344,7 @@ def publish(self, feed_key, data, metadata = None, shared_user=None, is_group=Fa
343
344
..code-block:: python
344
345
345
346
client.publish('temperature, 'thirty degrees')
346
-
347
+
347
348
Example of publishing an integer to Adafruit IO on group 'weatherstation'.
348
349
..code-block:: python
349
350
@@ -353,7 +354,7 @@ def publish(self, feed_key, data, metadata = None, shared_user=None, is_group=Fa
353
354
..code-block:: python
354
355
355
356
client.publish('temperature', shared_user='myfriend')
356
-
357
+
357
358
Example of publishing a value along with locational metadata to a feed.
358
359
..code-block:: python
359
360
@@ -371,11 +372,12 @@ def publish(self, feed_key, data, metadata = None, shared_user=None, is_group=Fa
371
372
if isinstance (data , int or float ):
372
373
data = str (data )
373
374
csv_string = data + "," + metadata
374
- self ._client .publish ("{0}/feeds/{1}/csv" .format (self ._user , feed_key ), csv_string )
375
+ self ._client .publish (
376
+ "{0}/feeds/{1}/csv" .format (self ._user , feed_key ), csv_string
377
+ )
375
378
else :
376
379
self ._client .publish ("{0}/feeds/{1}" .format (self ._user , feed_key ), data )
377
380
378
-
379
381
def get (self , feed_key ):
380
382
"""Calling this method will make Adafruit IO publish the most recent
381
383
value on feed_key.
@@ -611,17 +613,17 @@ def receive_time(self):
611
613
https://circuitpython.readthedocs.io/en/latest/shared-bindings/time/__init__.html#time.struct_time
612
614
"""
613
615
path = self ._compose_path ("integrations/time/struct.json" )
614
- time = self ._get (path )
615
- return struct_time (
616
+ time_struct = self ._get (path )
617
+ return time . struct_time (
616
618
(
617
- time ["year" ],
618
- time ["mon" ],
619
- time ["mday" ],
620
- time ["hour" ],
621
- time ["min" ],
622
- time ["sec" ],
623
- time ["wday" ],
624
- time ["yday" ],
625
- time ["isdst" ],
619
+ time_struct ["year" ],
620
+ time_struct ["mon" ],
621
+ time_struct ["mday" ],
622
+ time_struct ["hour" ],
623
+ time_struct ["min" ],
624
+ time_struct ["sec" ],
625
+ time_struct ["wday" ],
626
+ time_struct ["yday" ],
627
+ time_struct ["isdst" ],
626
628
)
627
629
)
0 commit comments