parent
9ef016e93d
commit
80b455a0eb
5 changed files with 29 additions and 12 deletions
|
|
@ -1 +1 @@
|
|||
__version__ = "2.0.0"
|
||||
__version__ = "2.0.11"
|
||||
|
|
@ -68,9 +68,12 @@ class Client(object):
|
|||
|
||||
|
||||
def _handle_error(self, response):
|
||||
# Handle explicit errors.
|
||||
# Throttling Error
|
||||
if response.status_code == 429:
|
||||
raise ThrottlingError()
|
||||
# Resource on AdafruitIO not Found Error
|
||||
elif response.status_code == 400:
|
||||
raise RequestError(response)
|
||||
# Handle all other errors (400 & 500 level HTTP responses)
|
||||
elif response.status_code >= 400:
|
||||
raise RequestError(response)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
import json
|
||||
import json, requests
|
||||
|
||||
# MQTT RC Error Types
|
||||
MQTT_ERRORS = [ 'Connection successful',
|
||||
|
|
@ -42,9 +42,9 @@ class RequestError(Exception):
|
|||
response.status_code, response.reason, error_message))
|
||||
|
||||
def _parse_error(self, response):
|
||||
content = response.json()
|
||||
try:
|
||||
content = json.loads(response.content)
|
||||
return ' - '.join(content['error'])
|
||||
return content['error']
|
||||
except ValueError:
|
||||
return ""
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# Author: Tony DiCola
|
||||
|
||||
# Import Adafruit IO REST client.
|
||||
from Adafruit_IO import Client
|
||||
from Adafruit_IO import Client, RequestError, Feed
|
||||
|
||||
# Set to your Adafruit IO key.
|
||||
# Remember, your key is a secret,
|
||||
|
|
@ -17,20 +17,34 @@ ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'
|
|||
# Create an instance of the REST client.
|
||||
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
|
||||
|
||||
# Assign a foo feed, if one exists already
|
||||
try:
|
||||
foo = aio.feeds('foo')
|
||||
except RequestError: # Doesn't exist, create a new feed
|
||||
feed = Feed(name="foo")
|
||||
foo = aio.create_feed(feed)
|
||||
|
||||
# Assign a test feed, if one exists already
|
||||
try:
|
||||
test = aio.feeds('test')
|
||||
except RequestError: # Doesn't exist, create a new feed
|
||||
feed = Feed(name="test")
|
||||
test = aio.create_feed(feed)
|
||||
|
||||
# Send a value to the feed 'Test'.
|
||||
aio.send_data('Test', 42)
|
||||
aio.send_data(test.key, 42)
|
||||
|
||||
# Send a string value 'bar' to the feed 'Foo'.
|
||||
aio.send_data('Foo', 'bar')
|
||||
aio.send_data(foo.key, 'bar')
|
||||
|
||||
# Now read the most recent value from the feed 'Test'. Notice that it comes
|
||||
# back as a string and should be converted to an int if performing calculations
|
||||
# on it.
|
||||
data = aio.receive('Test')
|
||||
data = aio.receive(test.key)
|
||||
print('Retrieved value from Test has attributes: {0}'.format(data))
|
||||
print('Latest value from Test: {0}'.format(data.value))
|
||||
|
||||
# Finally read the most revent value from feed 'Foo'.
|
||||
data = aio.receive('Foo')
|
||||
data = aio.receive(foo.key)
|
||||
print('Retrieved value from Foo has attributes: {0}'.format(data))
|
||||
print('Latest value from Foo: {0}'.format(data.value))
|
||||
|
|
|
|||
4
setup.py
4
setup.py
|
|
@ -36,6 +36,8 @@ classifiers = ['Development Status :: 5 - Production/Stable',
|
|||
'License :: OSI Approved :: MIT License',
|
||||
'Intended Audience :: Developers',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Programming Language :: Python :: 3.6',
|
||||
'Topic :: Home Automation',
|
||||
'Topic :: Software Development']
|
||||
|
|
@ -59,8 +61,6 @@ setup(
|
|||
|
||||
version = verstr,
|
||||
install_requires = ["requests", "paho-mqtt"],
|
||||
python_requires = ">=3.6.0",
|
||||
|
||||
|
||||
|
||||
packages = ['Adafruit_IO'],
|
||||
|
|
|
|||
Loading…
Reference in a new issue