Skip to content

Commit d030d22

Browse files
author
Rodrigo Argumedo
committed
Create send_batch_data method
Additionally, Define the data variable as an empty array.
1 parent 817574c commit d030d22

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

adafruit_io/adafruit_io.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,26 @@ def send_data(self, feed_key, data, metadata=None, precision=None):
565565
payload = self._create_data(data, metadata)
566566
self._post(path, payload)
567567

568+
def send_batch_data(self, feed_key, data, metadata=None, precision=None):
569+
"""
570+
Sends a batch array of data to a specified Adafruit IO feed
571+
:param str feed_key: Adafruit IO feed key
572+
:param str data: Data to send
573+
:param dict metadata: Optional metadata associated with the data
574+
:param int precision: Optional amount of precision points to send with floating point data
575+
"""
576+
data = []
577+
path = self._compose_path("feeds/{0}/data/batch".format(feed_key))
578+
if precision:
579+
try:
580+
data = round(data, precision)
581+
except NotImplementedError as err:
582+
raise NotImplementedError(
583+
"Precision requires a floating point value"
584+
) from err
585+
payload = self._create_data(data, metadata)
586+
self._post(path, payload)
587+
568588
def receive_all_data(self, feed_key):
569589
"""
570590
Get all data values from a specified Adafruit IO feed. Data is

0 commit comments

Comments
 (0)