Skip to content

Commit 52f8b9c

Browse files
authored
Merge pull request #13 from brentru/add-precision-sends
Add optional precision kwarg for formatting floating point data
2 parents 7fd0783 + 8851e82 commit 52f8b9c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

adafruit_io/adafruit_io.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,20 @@ def _delete(self, path):
133133
return response.json()
134134

135135
# Data
136-
def send_data(self, feed_key, data, metadata=None):
136+
def send_data(self, feed_key, data, metadata=None, precision=None):
137137
"""
138138
Sends value data to a specified Adafruit IO feed.
139139
:param str feed_key: Adafruit IO feed key
140140
:param str data: Data to send to the Adafruit IO feed
141141
:param dict metadata: Optional metadata associated with the data
142+
:param int precision: Optional amount of precision points to send with floating point data
142143
"""
143144
path = self._compose_path("feeds/{0}/data".format(feed_key))
145+
if precision:
146+
try:
147+
data = round(data, precision)
148+
except NotImplementedError: # received a non-float value
149+
raise NotImplementedError('Precision requires a floating point value')
144150
payload = self._create_data(data, metadata)
145151
self._post(path, payload)
146152

0 commit comments

Comments
 (0)