@@ -72,20 +72,23 @@ def __init__(self, username, key, proxies=None, base_url='https://io.adafruit.co
72
72
@staticmethod
73
73
def to_red (data ):
74
74
"""Hex color feed to red channel.
75
+
75
76
:param int data: Color value, in hexadecimal.
76
77
"""
77
78
return ((int (data [1 ], 16 ))* 16 ) + int (data [2 ], 16 )
78
79
79
80
@staticmethod
80
81
def to_green (data ):
81
82
"""Hex color feed to green channel.
83
+
82
84
:param int data: Color value, in hexadecimal.
83
85
"""
84
86
return (int (data [3 ], 16 ) * 16 ) + int (data [4 ], 16 )
85
87
86
88
@staticmethod
87
89
def to_blue (data ):
88
90
"""Hex color feed to blue channel.
91
+
89
92
:param int data: Color value, in hexadecimal.
90
93
"""
91
94
return (int (data [5 ], 16 ) * 16 ) + int (data [6 ], 16 )
@@ -153,6 +156,7 @@ def send_data(self, feed, value, metadata=None, precision=None):
153
156
specified value to the feed identified by either name, key, or ID.
154
157
Returns a Data instance with details about the newly appended row of data.
155
158
Note that send_data now operates the same as append.
159
+
156
160
:param string feed: Name/Key/ID of Adafruit IO feed.
157
161
:param string value: Value to send.
158
162
:param dict metadata: Optional metadata associated with the value.
@@ -173,6 +177,7 @@ def send_batch_data(self, feed, data_list):
173
177
ID, feed key, or feed name. Data must be an instance of the Data class
174
178
with at least a value property set on it. Returns a Data instance with
175
179
details about the newly appended row of data.
180
+
176
181
:param string feed: Name/Key/ID of Adafruit IO feed.
177
182
:param Data data_list: Multiple data values.
178
183
"""
@@ -185,21 +190,28 @@ def append(self, feed, value):
185
190
specified value to the feed identified by either name, key, or ID.
186
191
Returns a Data instance with details about the newly appended row of data.
187
192
Note that unlike send the feed should exist before calling append.
193
+
188
194
:param string feed: Name/Key/ID of Adafruit IO feed.
189
195
:param string value: Value to append to feed.
190
196
"""
191
197
return self .create_data (feed , Data (value = value ))
192
198
193
- def receive_time (self ):
194
- """Returns a struct_time from the Adafruit IO Server based on the device's IP address.
199
+ def receive_time (self , timezone = None ):
200
+ """Returns a struct_time from the Adafruit IO Server based on requested
201
+ timezone, or automatically based on the device's IP address.
195
202
https://docs.python.org/3.7/library/time.html#time.struct_time
203
+
204
+ :param string timezone: Optional timezone to return the time in.
205
+ See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
196
206
"""
197
207
path = 'integrations/time/struct.json'
208
+ if timezone :
209
+ path += f'?tz={ timezone } '
198
210
return self ._parse_time_struct (self ._get (path ))
199
211
200
212
@staticmethod
201
213
def _parse_time_struct (time_dict : dict ) -> time .struct_time :
202
- """Parse the time data returned by the server and return a time_struct
214
+ """Parse the time data returned by the server and return a time_struct
203
215
204
216
Corrects for the weekday returned by the server in Sunday=0 format
205
217
(Python expects Monday=0)
@@ -211,6 +223,7 @@ def _parse_time_struct(time_dict: dict) -> time.struct_time:
211
223
212
224
def receive_weather (self , weather_id = None ):
213
225
"""Adafruit IO Weather Service, Powered by Dark Sky
226
+
214
227
:param int id: optional ID for retrieving a specified weather record.
215
228
"""
216
229
if weather_id :
@@ -222,6 +235,7 @@ def receive_weather(self, weather_id=None):
222
235
def receive_random (self , randomizer_id = None ):
223
236
"""Access to Adafruit IO's Random Data
224
237
service.
238
+
225
239
:param int randomizer_id: optional ID for retrieving a specified randomizer.
226
240
"""
227
241
if randomizer_id :
@@ -233,6 +247,7 @@ def receive_random(self, randomizer_id=None):
233
247
def receive (self , feed ):
234
248
"""Retrieve the most recent value for the specified feed. Returns a Data
235
249
instance whose value property holds the retrieved value.
250
+
236
251
:param string feed: Name/Key/ID of Adafruit IO feed.
237
252
"""
238
253
path = "feeds/{0}/data/last" .format (feed )
@@ -241,6 +256,7 @@ def receive(self, feed):
241
256
def receive_next (self , feed ):
242
257
"""Retrieve the next unread value from the specified feed. Returns a Data
243
258
instance whose value property holds the retrieved value.
259
+
244
260
:param string feed: Name/Key/ID of Adafruit IO feed.
245
261
"""
246
262
path = "feeds/{0}/data/next" .format (feed )
@@ -249,6 +265,7 @@ def receive_next(self, feed):
249
265
def receive_previous (self , feed ):
250
266
"""Retrieve the previous unread value from the specified feed. Returns a
251
267
Data instance whose value property holds the retrieved value.
268
+
252
269
:param string feed: Name/Key/ID of Adafruit IO feed.
253
270
"""
254
271
path = "feeds/{0}/data/previous" .format (feed )
@@ -257,6 +274,7 @@ def receive_previous(self, feed):
257
274
def data (self , feed , data_id = None , max_results = DEFAULT_PAGE_LIMIT ):
258
275
"""Retrieve data from a feed. If data_id is not specified then all the data
259
276
for the feed will be returned in an array.
277
+
260
278
:param string feed: Name/Key/ID of Adafruit IO feed.
261
279
:param string data_id: ID of the piece of data to delete.
262
280
:param int max_results: The maximum number of results to return. To
@@ -306,6 +324,7 @@ def create_data(self, feed, data):
306
324
"""Create a new row of data in the specified feed.
307
325
Returns a Data instance with details about the newly
308
326
appended row of data.
327
+
309
328
:param string feed: Name/Key/ID of Adafruit IO feed.
310
329
:param Data data: Instance of the Data class. Must have a value property set.
311
330
"""
@@ -314,6 +333,7 @@ def create_data(self, feed, data):
314
333
315
334
def delete (self , feed , data_id ):
316
335
"""Delete data from a feed.
336
+
317
337
:param string feed: Name/Key/ID of Adafruit IO feed.
318
338
:param string data_id: ID of the piece of data to delete.
319
339
"""
@@ -324,6 +344,7 @@ def delete(self, feed, data_id):
324
344
def feeds (self , feed = None ):
325
345
"""Retrieve a list of all feeds, or the specified feed. If feed is not
326
346
specified a list of all feeds will be returned.
347
+
327
348
:param string feed: Name/Key/ID of Adafruit IO feed, defaults to None.
328
349
"""
329
350
if feed is None :
@@ -334,6 +355,7 @@ def feeds(self, feed=None):
334
355
335
356
def create_feed (self , feed , group_key = None ):
336
357
"""Create the specified feed.
358
+
337
359
:param string feed: Key of Adafruit IO feed.
338
360
:param group_key group: Group to place new feed in.
339
361
"""
@@ -347,6 +369,7 @@ def create_feed(self, feed, group_key=None):
347
369
348
370
def delete_feed (self , feed ):
349
371
"""Delete the specified feed.
372
+
350
373
:param string feed: Name/Key/ID of Adafruit IO feed.
351
374
"""
352
375
path = "feeds/{0}" .format (feed )
@@ -355,6 +378,7 @@ def delete_feed(self, feed):
355
378
# Group functionality.
356
379
def groups (self , group = None ):
357
380
"""Retrieve a list of all groups, or the specified group.
381
+
358
382
:param string group: Name/Key/ID of Adafruit IO Group. Defaults to None.
359
383
"""
360
384
if group is None :
@@ -365,13 +389,15 @@ def groups(self, group=None):
365
389
366
390
def create_group (self , group ):
367
391
"""Create the specified group.
392
+
368
393
:param string group: Name/Key/ID of Adafruit IO Group.
369
394
"""
370
395
path = "groups/"
371
396
return Group .from_dict (self ._post (path , group ._asdict ()))
372
397
373
398
def delete_group (self , group ):
374
399
"""Delete the specified group.
400
+
375
401
:param string group: Name/Key/ID of Adafruit IO Group.
376
402
"""
377
403
path = "groups/{0}" .format (group )
@@ -380,6 +406,7 @@ def delete_group(self, group):
380
406
# Dashboard functionality.
381
407
def dashboards (self , dashboard = None ):
382
408
"""Retrieve a list of all dashboards, or the specified dashboard.
409
+
383
410
:param string dashboard: Key of Adafruit IO Dashboard. Defaults to None.
384
411
"""
385
412
if dashboard is None :
@@ -390,13 +417,15 @@ def dashboards(self, dashboard=None):
390
417
391
418
def create_dashboard (self , dashboard ):
392
419
"""Create the specified dashboard.
420
+
393
421
:param Dashboard dashboard: Dashboard object to create
394
422
"""
395
423
path = "dashboards/"
396
424
return Dashboard .from_dict (self ._post (path , dashboard ._asdict ()))
397
425
398
426
def delete_dashboard (self , dashboard ):
399
427
"""Delete the specified dashboard.
428
+
400
429
:param string dashboard: Key of Adafruit IO Dashboard.
401
430
"""
402
431
path = "dashboards/{0}" .format (dashboard )
@@ -405,6 +434,7 @@ def delete_dashboard(self, dashboard):
405
434
# Block functionality.
406
435
def blocks (self , dashboard , block = None ):
407
436
"""Retrieve a list of all blocks from a dashboard, or the specified block.
437
+
408
438
:param string dashboard: Key of Adafruit IO Dashboard.
409
439
:param string block: id of Adafruit IO Block. Defaults to None.
410
440
"""
@@ -416,6 +446,7 @@ def blocks(self, dashboard, block=None):
416
446
417
447
def create_block (self , dashboard , block ):
418
448
"""Create the specified block under the specified dashboard.
449
+
419
450
:param string dashboard: Key of Adafruit IO Dashboard.
420
451
:param Block block: Block object to create under dashboard
421
452
"""
@@ -424,6 +455,7 @@ def create_block(self, dashboard, block):
424
455
425
456
def delete_block (self , dashboard , block ):
426
457
"""Delete the specified block.
458
+
427
459
:param string dashboard: Key of Adafruit IO Dashboard.
428
460
:param string block: id of Adafruit IO Block.
429
461
"""
@@ -433,6 +465,7 @@ def delete_block(self, dashboard, block):
433
465
# Layout functionality.
434
466
def layouts (self , dashboard ):
435
467
"""Retrieve the layouts array from a dashboard
468
+
436
469
:param string dashboard: key of Adafruit IO Dashboard.
437
470
"""
438
471
path = "dashboards/{0}" .format (dashboard )
@@ -441,6 +474,7 @@ def layouts(self, dashboard):
441
474
442
475
def update_layout (self , dashboard , layout ):
443
476
"""Update the layout of the specified dashboard.
477
+
444
478
:param string dashboard: Key of Adafruit IO Dashboard.
445
479
:param Layout layout: Layout object to update under dashboard
446
480
"""
0 commit comments