19
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
20
# SOFTWARE.
21
21
import json
22
- import pkg_resources
23
22
import platform
23
+ import pkg_resources
24
24
# import logging
25
25
26
26
import requests
@@ -58,6 +58,33 @@ def __init__(self, username, key, proxies=None, base_url='https://io.adafruit.co
58
58
# constructing the path.
59
59
self .base_url = base_url .rstrip ('/' )
60
60
61
+ @staticmethod
62
+ def to_red (data ):
63
+ """Hex color feed to red channel.
64
+ :param int data: Color value, in hexadecimal.
65
+ """
66
+ return ((int (data [1 ], 16 ))* 16 ) + int (data [2 ], 16 )
67
+
68
+ @staticmethod
69
+ def to_green (data ):
70
+ """Hex color feed to green channel.
71
+ :param int data: Color value, in hexadecimal.
72
+ """
73
+ return (int (data [3 ], 16 ) * 16 ) + int (data [4 ], 16 )
74
+
75
+ @staticmethod
76
+ def to_blue (data ):
77
+ """Hex color feed to blue channel.
78
+ :param int data: Color value, in hexadecimal.
79
+ """
80
+ return (int (data [5 ], 16 ) * 16 ) + int (data [6 ], 16 )
81
+
82
+ @staticmethod
83
+ def _headers (given ):
84
+ headers = default_headers .copy ()
85
+ headers .update (given )
86
+ return headers
87
+
61
88
@staticmethod
62
89
def _create_payload (value , metadata ):
63
90
if metadata is not None :
@@ -84,20 +111,14 @@ def _compose_url(self, path, is_time=None):
84
111
return '{0}/api/{1}/{2}' .format (self .base_url , 'v2' , path )
85
112
return '{0}/api/{1}/{2}/{3}' .format (self .base_url , 'v2' , self .username , path )
86
113
87
- def _headers (self , given ):
88
- headers = default_headers .copy ()
89
- headers .update (given )
90
- return headers
91
-
92
114
def _get (self , path , is_time = None ):
93
115
response = requests .get (self ._compose_url (path , is_time ),
94
116
headers = self ._headers ({'X-AIO-Key' : self .key }),
95
117
proxies = self .proxies )
96
118
self ._handle_error (response )
97
119
if not is_time :
98
120
return response .json ()
99
- else : # time doesn't need to serialize into json, just return text
100
- return response .text
121
+ return response .text
101
122
102
123
def _post (self , path , data ):
103
124
response = requests .post (self ._compose_url (path ),
@@ -111,8 +132,8 @@ def _post(self, path, data):
111
132
def _delete (self , path ):
112
133
response = requests .delete (self ._compose_url (path ),
113
134
headers = self ._headers ({'X-AIO-Key' : self .key ,
114
- 'Content-Type' : 'application/json' }),
115
- proxies = self .proxies )
135
+ 'Content-Type' : 'application/json' }),
136
+ proxies = self .proxies )
116
137
self ._handle_error (response )
117
138
118
139
# Data functionality.
@@ -241,24 +262,6 @@ def delete(self, feed, data_id):
241
262
path = "feeds/{0}/data/{1}" .format (feed , data_id )
242
263
self ._delete (path )
243
264
244
- def toRed (self , data ):
245
- """Hex color feed to red channel.
246
- :param int data: Color value, in hexadecimal.
247
- """
248
- return ((int (data [1 ], 16 ))* 16 ) + int (data [2 ], 16 )
249
-
250
- def toGreen (self , data ):
251
- """Hex color feed to green channel.
252
- :param int data: Color value, in hexadecimal.
253
- """
254
- return (int (data [3 ], 16 ) * 16 ) + int (data [4 ], 16 )
255
-
256
- def toBlue (self , data ):
257
- """Hex color feed to blue channel.
258
- :param int data: Color value, in hexadecimal.
259
- """
260
- return (int (data [5 ], 16 ) * 16 ) + int (data [6 ], 16 )
261
-
262
265
# feed functionality.
263
266
def feeds (self , feed = None ):
264
267
"""Retrieve a list of all feeds, or the specified feed. If feed is not
0 commit comments