1919# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020# SOFTWARE.
2121import json
22- import pkg_resources
2322import platform
23+ import pkg_resources
2424# import logging
2525
2626import requests
@@ -58,6 +58,33 @@ def __init__(self, username, key, proxies=None, base_url='https://io.adafruit.co
5858 # constructing the path.
5959 self .base_url = base_url .rstrip ('/' )
6060
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+
6188 @staticmethod
6289 def _create_payload (value , metadata ):
6390 if metadata is not None :
@@ -84,20 +111,14 @@ def _compose_url(self, path, is_time=None):
84111 return '{0}/api/{1}/{2}' .format (self .base_url , 'v2' , path )
85112 return '{0}/api/{1}/{2}/{3}' .format (self .base_url , 'v2' , self .username , path )
86113
87- def _headers (self , given ):
88- headers = default_headers .copy ()
89- headers .update (given )
90- return headers
91-
92114 def _get (self , path , is_time = None ):
93115 response = requests .get (self ._compose_url (path , is_time ),
94116 headers = self ._headers ({'X-AIO-Key' : self .key }),
95117 proxies = self .proxies )
96118 self ._handle_error (response )
97119 if not is_time :
98120 return response .json ()
99- else : # time doesn't need to serialize into json, just return text
100- return response .text
121+ return response .text
101122
102123 def _post (self , path , data ):
103124 response = requests .post (self ._compose_url (path ),
@@ -111,8 +132,8 @@ def _post(self, path, data):
111132 def _delete (self , path ):
112133 response = requests .delete (self ._compose_url (path ),
113134 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 )
116137 self ._handle_error (response )
117138
118139 # Data functionality.
@@ -241,24 +262,6 @@ def delete(self, feed, data_id):
241262 path = "feeds/{0}/data/{1}" .format (feed , data_id )
242263 self ._delete (path )
243264
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-
262265 # feed functionality.
263266 def feeds (self , feed = None ):
264267 """Retrieve a list of all feeds, or the specified feed. If feed is not
0 commit comments