@@ -61,18 +61,13 @@ def __init__(self, username, key, proxies=None, base_url='https://io.adafruit.co
6161 @staticmethod
6262 def _create_payload (value , metadata ):
6363 if metadata is not None :
64- payload = Data (value = value ,lat = metadata ['lat' ], lon = metadata ['lon' ],
65- ele = metadata ['ele' ], created_at = metadata ['created_at' ])
64+ payload = Data (value = value , lat = metadata ['lat' ], lon = metadata ['lon' ],
65+ ele = metadata ['ele' ], created_at = metadata ['created_at' ])
6666 return payload
6767 return Data (value = value )
6868
69- def _compose_url (self , path , is_time = None ):
70- if is_time : # return a call to https://io.adafruit.com/api/v2/time/{unit}
71- return '{0}/api/{1}/{2}' .format (self .base_url , 'v2' , path )
72- else :
73- return '{0}/api/{1}/{2}/{3}' .format (self .base_url , 'v2' , self .username , path )
74-
75- def _handle_error (self , response ):
69+ @staticmethod
70+ def _handle_error (response ):
7671 # Throttling Error
7772 if response .status_code == 429 :
7873 raise ThrottlingError ()
@@ -84,6 +79,11 @@ def _handle_error(self, response):
8479 raise RequestError (response )
8580 # Else do nothing if there was no error.
8681
82+ def _compose_url (self , path , is_time = None ):
83+ if is_time : # return a call to https://io.adafruit.com/api/v2/time/{unit}
84+ return '{0}/api/{1}/{2}' .format (self .base_url , 'v2' , path )
85+ return '{0}/api/{1}/{2}/{3}' .format (self .base_url , 'v2' , self .username , path )
86+
8787 def _headers (self , given ):
8888 headers = default_headers .copy ()
8989 headers .update (given )
@@ -111,7 +111,7 @@ def _post(self, path, data):
111111 def _delete (self , path ):
112112 response = requests .delete (self ._compose_url (path ),
113113 headers = self ._headers ({'X-AIO-Key' : self .key ,
114- 'Content-Type' : 'application/json' }),
114+ 'Content-Type' : 'application/json' }),
115115 proxies = self .proxies )
116116 self ._handle_error (response )
117117
@@ -130,7 +130,7 @@ def send_data(self, feed, value, metadata=None, precision=None):
130130 try :
131131 value = round (value , precision )
132132 except NotImplementedError :
133- raise NotImplementedError ("Using the precision kwarg requires a floating point value" )
133+ raise NotImplementedError ("Using the precision kwarg requires a float value" )
134134 payload = self ._create_payload (value , metadata )
135135 return self .create_data (feed , payload )
136136
@@ -164,26 +164,26 @@ def receive_time(self, time):
164164 """
165165 timepath = "time/{0}" .format (time )
166166 return self ._get (timepath , is_time = True )
167-
167+
168168 def receive_weather (self , weather_id = None ):
169169 """Adafruit IO Weather Service, Powered by Dark Sky
170170 :param int id: optional ID for retrieving a specified weather record.
171171 """
172172 if weather_id :
173- weather_path = "integrations/weather/{0}" .format (weather_id )
173+ weather_path = "integrations/weather/{0}" .format (weather_id )
174174 else :
175- weather_path = "integrations/weather"
175+ weather_path = "integrations/weather"
176176 return self ._get (weather_path )
177-
177+
178178 def receive_random (self , id = None ):
179179 """Access to Adafruit IO's Random Data
180180 service.
181181 :param int id: optional ID for retrieving a specified randomizer.
182182 """
183183 if id :
184- random_path = "integrations/words/{0}" .format (id )
184+ random_path = "integrations/words/{0}" .format (id )
185185 else :
186- random_path = "integrations/words"
186+ random_path = "integrations/words"
187187 return self ._get (random_path )
188188
189189 def receive (self , feed ):
@@ -195,7 +195,7 @@ def receive(self, feed):
195195 return Data .from_dict (self ._get (path ))
196196
197197 def receive_next (self , feed ):
198- """Retrieve the next unread value from the specified feed. Returns a Data
198+ """Retrieve the next unread value from the specified feed. Returns a Data
199199 instance whose value property holds the retrieved value.
200200 :param string feed: Name/Key/ID of Adafruit IO feed.
201201 """
@@ -225,10 +225,10 @@ def data(self, feed, data_id=None):
225225
226226 def create_data (self , feed , data ):
227227 """Create a new row of data in the specified feed.
228- Returns a Data instance with details about the newly
228+ Returns a Data instance with details about the newly
229229 appended row of data.
230230 :param string feed: Name/Key/ID of Adafruit IO feed.
231- :param Data data: Instance of the Data class. Must have a value property set.
231+ :param Data data: Instance of the Data class. Must have a value property set.
232232 """
233233 path = "feeds/{0}/data" .format (feed )
234234 return Data .from_dict (self ._post (path , data ._asdict ()))
@@ -248,7 +248,7 @@ def toRed(self, data):
248248 return ((int (data [1 ], 16 ))* 16 ) + int (data [2 ], 16 )
249249
250250 def toGreen (self , data ):
251- """Hex color feed to green channel.
251+ """Hex color feed to green channel.
252252 :param int data: Color value, in hexadecimal.
253253 """
254254 return (int (data [3 ], 16 ) * 16 ) + int (data [4 ], 16 )
@@ -310,4 +310,4 @@ def delete_group(self, group):
310310 :param string group: Name/Key/ID of Adafruit IO Group.
311311 """
312312 path = "groups/{0}" .format (group )
313- self ._delete (path )
313+ self ._delete (path )
0 commit comments