@@ -109,16 +109,34 @@ def _delete(self, path):
109
109
proxies = self .proxies )
110
110
self ._handle_error (response )
111
111
112
+ @staticmethod
113
+ def _create_payload (value , metadata ):
114
+ """
115
+ """
116
+ if metadata is not None :
117
+ payload = Data (value = value ,lat = metadata ['lat' ], lon = metadata ['lon' ],
118
+ ele = metadata ['ele' ], created_at = metadata ['created_at' ])
119
+ return payload
120
+ return Data (value = value )
121
+
112
122
# Data functionality.
113
- def send_data (self , feed , value ):
123
+ def send_data (self , feed , value , metadata = None , precision = None ):
114
124
"""Helper function to simplify adding a value to a feed. Will append the
115
125
specified value to the feed identified by either name, key, or ID.
116
126
Returns a Data instance with details about the newly appended row of data.
117
127
Note that send_data now operates the same as append.
118
128
:param string feed: Name/Key/ID of Adafruit IO feed.
119
129
:param string value: Value to send.
130
+ :param dict metadata: Optional metadata associated with the value.
131
+ :param int precision: Optional amount of precision points to send.
120
132
"""
121
- return self .create_data (feed , Data (value = value ))
133
+ if precision :
134
+ try :
135
+ value = round (value , precision )
136
+ except NotImplementedError :
137
+ raise NotImplementedError ("Using the precision kwarg requires a floating point value" )
138
+ payload = self ._create_payload (value , metadata )
139
+ return self .create_data (feed , payload )
122
140
123
141
send = send_data
124
142
0 commit comments