Skip to content

Commit d513f79

Browse files
committed
Added get_all_data and linted
1 parent 2fcef79 commit d513f79

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

adafruit_io/adafruit_io.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ def __init__(self, mqtt_client):
7070
# MiniMQTT's username kwarg is optional, IO requires a username
7171
try:
7272
self._user = self._client.user
73-
except:
73+
except Exception as err:
7474
raise TypeError(
7575
"Adafruit IO requires a username, please set one in MiniMQTT"
76-
)
76+
) from err
7777
# User-defined MQTT callback methods must be init'd to None
7878
self.on_connect = None
7979
self.on_disconnect = None
@@ -105,17 +105,17 @@ def reconnect(self):
105105
"""
106106
try:
107107
self._client.reconnect()
108-
except:
109-
raise AdafruitIO_MQTTError("Unable to reconnect to Adafruit IO.")
108+
except Exception as err:
109+
raise AdafruitIO_MQTTError("Unable to reconnect to Adafruit IO.") from err
110110

111111
def connect(self):
112112
"""Connects to the Adafruit IO MQTT Broker.
113113
Must be called before any other API methods are called.
114114
"""
115115
try:
116116
self._client.connect()
117-
except:
118-
raise AdafruitIO_MQTTError("Unable to connect to Adafruit IO.")
117+
except Exception as err:
118+
raise AdafruitIO_MQTTError("Unable to connect to Adafruit IO.") from err
119119

120120
def disconnect(self):
121121
"""Disconnects from Adafruit IO MQTT Broker.
@@ -556,11 +556,22 @@ def send_data(self, feed_key, data, metadata=None, precision=None):
556556
if precision:
557557
try:
558558
data = round(data, precision)
559-
except NotImplementedError: # received a non-float value
560-
raise NotImplementedError("Precision requires a floating point value")
559+
except NotImplementedError as err: # received a non-float value
560+
raise NotImplementedError(
561+
"Precision requires a floating point value"
562+
) from err
561563
payload = self._create_data(data, metadata)
562564
self._post(path, payload)
563565

566+
def receive_all_data(self, feed_key):
567+
"""
568+
Get all data values from a specified Adafruit IO feed. Data is
569+
returned in reverse order.
570+
:param str feed_key: Adafruit IO feed key
571+
"""
572+
path = self._compose_path("feeds/{0}/data".format(feed_key))
573+
return self._get(path)
574+
564575
def receive_data(self, feed_key):
565576
"""
566577
Return the most recent value for the specified feed.

adafruit_io/adafruit_io_errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AdafruitIO_ThrottleError(Exception):
3131
"""Adafruit IO request error class for rate-limiting"""
3232

3333
def __init__(self):
34-
super(AdafruitIO_ThrottleError, self).__init__(
34+
super().__init__(
3535
"Number of Adafruit IO Requests exceeded! \
3636
Please try again in 30 seconds.."
3737
)
@@ -43,7 +43,7 @@ class AdafruitIO_RequestError(Exception):
4343
def __init__(self, response):
4444
response_content = response.json()
4545
error = response_content["error"]
46-
super(AdafruitIO_RequestError, self).__init__(
46+
super().__init__(
4747
"Adafruit IO Error {0}: {1}".format(response.status_code, error)
4848
)
4949

@@ -52,4 +52,4 @@ class AdafruitIO_MQTTError(Exception):
5252
"""Adafruit IO MQTT error class"""
5353

5454
def __init__(self, response):
55-
super(AdafruitIO_MQTTError, self).__init__("MQTT Error: {0}".format(response))
55+
super().__init__("MQTT Error: {0}".format(response))

0 commit comments

Comments
 (0)