make weather_id an optional param, update example
This commit is contained in:
parent
fbbfe8ffae
commit
b6debfc9f1
3 changed files with 21 additions and 67 deletions
|
|
@ -162,11 +162,14 @@ class Client(object):
|
|||
timepath = "time/{0}".format(time)
|
||||
return self._get(timepath, is_time=True)
|
||||
|
||||
def receive_weather(self, weather_id):
|
||||
"""Get the specified weather record with current weather and all available forecast information.
|
||||
:param int id: ID for forecast
|
||||
def receive_weather(self, weather_id=None):
|
||||
"""Adafruit IO Weather Service, Powered by Dark Sky
|
||||
:param int id: optional ID for retrieving a specified weather record.
|
||||
"""
|
||||
weatherpath = "integrations/weather/{0}".format(weather_id)
|
||||
if weather_id:
|
||||
weatherpath = "integrations/weather/{0}".format(weather_id)
|
||||
else:
|
||||
weatherpath = "integrations/weather"
|
||||
return self._get(weatherpath)
|
||||
|
||||
def receive(self, feed):
|
||||
|
|
|
|||
|
|
@ -1,24 +1,29 @@
|
|||
"""
|
||||
Example of getting a darkskies forecast
|
||||
from Adafruit IO.
|
||||
Example of getting a forecast from Adafruit IO
|
||||
Note: This functionality is for IO PLUS users ONLY.
|
||||
|
||||
Author: Brent Rubell for Adafruit Industries
|
||||
"""
|
||||
# import Adafruit IO REST client.
|
||||
from Adafruit_IO import Client, Feed, RequestError
|
||||
|
||||
# Set to your Adafruit IO key.
|
||||
# Remember, your key is a secret,
|
||||
# so make sure not to publish it when you publish this code!
|
||||
ADAFRUIT_IO_KEY = 'PASS'
|
||||
|
||||
# Set to your Adafruit IO username.
|
||||
# (go to https://accounts.adafruit.com to find your username)
|
||||
ADAFRUIT_IO_USERNAME = 'USER'
|
||||
|
||||
# Set to your Adafruit IO key.
|
||||
# Remember, your key is a secret,
|
||||
# so make sure not to publish it when you publish this code!
|
||||
ADAFRUIT_IO_KEY = 'PASSWORD'
|
||||
|
||||
|
||||
# Create an instance of the REST client.
|
||||
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
|
||||
|
||||
print('Get all weather integration records without their current forecast values.')
|
||||
records = aio.receive_weather()
|
||||
print(records)
|
||||
|
||||
|
||||
print('Get the specified weather record with current weather and all available forecast information.')
|
||||
forecast = aio.receive_weather(2153)
|
||||
|
||||
print(forecast)
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
"""
|
||||
'digital_in.py'
|
||||
==================================
|
||||
Example of sending button values
|
||||
to an Adafruit IO feed.
|
||||
|
||||
Author(s): Brent Rubell, Todd Treece
|
||||
"""
|
||||
# Import standard python modules
|
||||
import time
|
||||
|
||||
# import Adafruit Blinka
|
||||
import board
|
||||
import digitalio
|
||||
|
||||
# import Adafruit IO REST client.
|
||||
from Adafruit_IO import Client, Feed, RequestError
|
||||
|
||||
# Set to your Adafruit IO key.
|
||||
# Remember, your key is a secret,
|
||||
# so make sure not to publish it when you publish this code!
|
||||
ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'
|
||||
|
||||
# Set to your Adafruit IO username.
|
||||
# (go to https://accounts.adafruit.com to find your username)
|
||||
ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'
|
||||
|
||||
# Create an instance of the REST client.
|
||||
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
|
||||
|
||||
try: # if we have a 'digital' feed
|
||||
digital = aio.feeds('digital')
|
||||
except RequestError: # create a digital feed
|
||||
feed = Feed(name="digital")
|
||||
digital = aio.create_feed(feed)
|
||||
|
||||
# button set up
|
||||
button = digitalio.DigitalInOut(board.D12)
|
||||
button.direction = digitalio.Direction.INPUT
|
||||
button.pull = digitalio.Pull.UP
|
||||
button_current = 0
|
||||
|
||||
|
||||
while True:
|
||||
if not button.value:
|
||||
button_current = 1
|
||||
else:
|
||||
button_current = 0
|
||||
|
||||
print('Button -> ', button_current)
|
||||
aio.send(digital.key, button_current)
|
||||
|
||||
# avoid timeout from adafruit io
|
||||
time.sleep(1)
|
||||
Loading…
Reference in a new issue