Skip to content

Commit

Permalink
Merge pull request #13 from brentru/add-precision-sends
Browse files Browse the repository at this point in the history
Add optional precision kwarg for formatting floating point data
  • Loading branch information
brentru committed Feb 26, 2019
2 parents 7fd0783 + 8851e82 commit 52f8b9c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion adafruit_io/adafruit_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,20 @@ def _delete(self, path):
return response.json()

# Data
def send_data(self, feed_key, data, metadata=None):
def send_data(self, feed_key, data, metadata=None, precision=None):
"""
Sends value data to a specified Adafruit IO feed.
:param str feed_key: Adafruit IO feed key
:param str data: Data to send to the Adafruit IO feed
:param dict metadata: Optional metadata associated with the data
:param int precision: Optional amount of precision points to send with floating point data
"""
path = self._compose_path("feeds/{0}/data".format(feed_key))
if precision:
try:
data = round(data, precision)
except NotImplementedError: # received a non-float value
raise NotImplementedError('Precision requires a floating point value')
payload = self._create_data(data, metadata)
self._post(path, payload)

Expand Down

0 comments on commit 52f8b9c

Please sign in to comment.