diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/adafruit_io/adafruit_io.py b/adafruit_io/adafruit_io.py index eb92da0..07f833e 100755 --- a/adafruit_io/adafruit_io.py +++ b/adafruit_io/adafruit_io.py @@ -488,9 +488,9 @@ def _handle_error(response): """ if response.status_code == 429: raise AdafruitIO_ThrottleError - elif response.status_code == 400: + if response.status_code == 400: raise AdafruitIO_RequestError(response) - elif response.status_code >= 400: + if response.status_code >= 400: raise AdafruitIO_RequestError(response) def _compose_path(self, path): diff --git a/docs/conf.py b/docs/conf.py index e3d0d23..a53846a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,35 +11,38 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.napoleon', - 'sphinx.ext.todo', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.todo", ] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit Adafruit_IO Library' -copyright = u'2019 Brent Rubell' -author = u'Brent Rubell' +project = u"Adafruit Adafruit_IO Library" +copyright = u"2019 Brent Rubell" +author = u"Brent Rubell" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -50,7 +54,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -62,7 +66,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -77,59 +81,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitAdafruit_ioLibrarydoc' +htmlhelp_basename = "AdafruitAdafruit_ioLibrarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitAdafruit_IOLibrary.tex', u'AdafruitAdafruit_IO Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitAdafruit_IOLibrary.tex", + u"AdafruitAdafruit_IO Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -137,8 +144,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitAdafruit_IOlibrary', u'Adafruit Adafruit_IO Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitAdafruit_IOlibrary", + u"Adafruit Adafruit_IO Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -147,7 +159,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitAdafruit_IOLibrary', u'Adafruit Adafruit_IO Library Documentation', - author, 'AdafruitAdafruit_IOLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitAdafruit_IOLibrary", + u"Adafruit Adafruit_IO Library Documentation", + author, + "AdafruitAdafruit_IOLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/http/adafruit_io_analog_in.py b/examples/http/adafruit_io_analog_in.py index 74bad6c..a1c4c53 100644 --- a/examples/http/adafruit_io_analog_in.py +++ b/examples/http/adafruit_io_analog_in.py @@ -6,8 +6,8 @@ import board import busio from digitalio import DigitalInOut -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager from analogio import AnalogIn +from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager # Import NeoPixel Library import neopixel @@ -37,35 +37,37 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards +status_light = neopixel.NeoPixel( + board.NEOPIXEL, 1, brightness=0.2 +) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" -#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) -aio_username = secrets['aio_username'] -aio_key = secrets['aio_key'] +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(aio_username, aio_key, wifi) try: # Get the 'light' feed from Adafruit IO - light_feed = io.get_feed('light') + light_feed = io.get_feed("light") except AdafruitIO_RequestError: # If no 'light' feed exists, create one - light_feed = io.create_new_feed('light') + light_feed = io.create_new_feed("light") # Set up an analog light sensor on the PyPortal adc = AnalogIn(board.LIGHT) while True: light_value = adc.value - print('Light Level: ', light_value) - print('Sending to Adafruit IO...') - io.send_data(light_feed['key'], light_value) - print('Sent!') + print("Light Level: ", light_value) + print("Sending to Adafruit IO...") + io.send_data(light_feed["key"], light_value) + print("Sent!") # delay sending to Adafruit IO time.sleep(SENSOR_DELAY) diff --git a/examples/http/adafruit_io_digital_out.py b/examples/http/adafruit_io_digital_out.py index b370db3..1f57b12 100644 --- a/examples/http/adafruit_io_digital_out.py +++ b/examples/http/adafruit_io_digital_out.py @@ -35,26 +35,28 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards +status_light = neopixel.NeoPixel( + board.NEOPIXEL, 1, brightness=0.2 +) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" -#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) -aio_username = secrets['aio_username'] -aio_key = secrets['aio_key'] +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(aio_username, aio_key, wifi) try: # Get the 'digital' feed from Adafruit IO - digital_feed = io.get_feed('digital') + digital_feed = io.get_feed("digital") except AdafruitIO_RequestError: # If no 'digital' feed exists, create one - digital_feed = io.create_new_feed('digital') + digital_feed = io.create_new_feed("digital") # Set up LED LED = DigitalInOut(board.D13) @@ -62,16 +64,16 @@ while True: # Get data from 'digital' feed - print('getting data from IO...') - feed_data = io.receive_data(digital_feed['key']) + print("getting data from IO...") + feed_data = io.receive_data(digital_feed["key"]) # Check if data is ON or OFF - if int(feed_data['value']) == 1: - print('received <- ON\n') - elif int(feed_data['value']) == 0: - print('received <= OFF\n') + if int(feed_data["value"]) == 1: + print("received <- ON\n") + elif int(feed_data["value"]) == 0: + print("received <= OFF\n") # Set the LED to the feed value - LED.value = int(feed_data['value']) + LED.value = int(feed_data["value"]) time.sleep(5) diff --git a/examples/http/adafruit_io_esp_at.py b/examples/http/adafruit_io_esp_at.py index c5b92d4..2a724c8 100644 --- a/examples/http/adafruit_io_esp_at.py +++ b/examples/http/adafruit_io_esp_at.py @@ -14,18 +14,24 @@ from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError # ESP32 AT -from adafruit_espatcontrol import adafruit_espatcontrol, adafruit_espatcontrol_wifimanager +from adafruit_espatcontrol import ( + adafruit_espatcontrol, + adafruit_espatcontrol_wifimanager, +) -#Use below for Most Boards +# Use below for Most Boards import neopixel -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards -#Uncomment below for ItsyBitsy M4# -#import adafruit_dotstar as dotstar -#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +status_light = neopixel.NeoPixel( + board.NEOPIXEL, 1, brightness=0.2 +) # Uncomment for Most Boards -#Uncomment below for Particle Argon# -#status_light = None +# Uncomment below for ItsyBitsy M4# +# import adafruit_dotstar as dotstar +# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) + +# Uncomment below for Particle Argon# +# status_light = None # Get wifi details and more from a secrets.py file try: @@ -52,33 +58,34 @@ esp_boot.value = True """ -esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200, - reset_pin=resetpin, rts_pin=rtspin, debug=False) +esp = adafruit_espatcontrol.ESP_ATcontrol( + uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False +) wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) -aio_username = secrets['aio_username'] -aio_key = secrets['aio_key'] +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(aio_username, aio_key, wifi) try: # Get the 'temperature' feed from Adafruit IO - temperature_feed = io.get_feed('temperature') + temperature_feed = io.get_feed("temperature") except AdafruitIO_RequestError: # If no 'temperature' feed exists, create one - temperature_feed = io.create_new_feed('temperature') + temperature_feed = io.create_new_feed("temperature") # Send random integer values to the feed random_value = randint(0, 50) -print('Sending {0} to temperature feed...'.format(random_value)) -io.send_data(temperature_feed['key'], random_value) -print('Data sent!') +print("Sending {0} to temperature feed...".format(random_value)) +io.send_data(temperature_feed["key"], random_value) +print("Data sent!") # Retrieve data value from the feed -print('Retrieving data from temperature feed...') -received_data = io.receive_data(temperature_feed['key']) -print('Data from temperature feed: ', received_data['value']) +print("Retrieving data from temperature feed...") +received_data = io.receive_data(temperature_feed["key"]) +print("Data from temperature feed: ", received_data["value"]) diff --git a/examples/http/adafruit_io_feeds.py b/examples/http/adafruit_io_feeds.py index f4c4969..5240957 100644 --- a/examples/http/adafruit_io_feeds.py +++ b/examples/http/adafruit_io_feeds.py @@ -33,30 +33,32 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards +status_light = neopixel.NeoPixel( + board.NEOPIXEL, 1, brightness=0.2 +) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" -#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) -aio_username = secrets['aio_username'] -aio_key = secrets['aio_key'] +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(aio_username, aio_key, wifi) # Create a new 'circuitpython' feed with a description -print('Creating new Adafruit IO feed...') -feed = io.create_new_feed('circuitpython', 'a Adafruit IO CircuitPython feed') +print("Creating new Adafruit IO feed...") +feed = io.create_new_feed("circuitpython", "a Adafruit IO CircuitPython feed") # List a specified feed -print('Retrieving new Adafruit IO feed...') -specified_feed = io.get_feed('circuitpython') +print("Retrieving new Adafruit IO feed...") +specified_feed = io.get_feed("circuitpython") print(specified_feed) # Delete a specified feed by feed key -print('Deleting feed...') -io.delete_feed(specified_feed['key']) -print('Feed deleted!') +print("Deleting feed...") +io.delete_feed(specified_feed["key"]) +print("Feed deleted!") diff --git a/examples/http/adafruit_io_groups.py b/examples/http/adafruit_io_groups.py index 32f8d25..436d321 100644 --- a/examples/http/adafruit_io_groups.py +++ b/examples/http/adafruit_io_groups.py @@ -33,30 +33,32 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards +status_light = neopixel.NeoPixel( + board.NEOPIXEL, 1, brightness=0.2 +) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" -#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) -aio_username = secrets['aio_username'] -aio_key = secrets['aio_key'] +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(aio_username, aio_key, wifi) # Create a new group -print('Creating a new Adafruit IO Group...') -sensor_group = io.create_new_group('envsensors', 'a group of environmental sensors') +print("Creating a new Adafruit IO Group...") +sensor_group = io.create_new_group("envsensors", "a group of environmental sensors") # Add the 'temperature' feed to the group -print('Adding feed temperature to group...') -io.add_feed_to_group(sensor_group['key'], 'temperature') +print("Adding feed temperature to group...") +io.add_feed_to_group(sensor_group["key"], "temperature") # Get info from the group print(sensor_group) # Delete the group -print('Deleting group...') -io.delete_group('envsensors') +print("Deleting group...") +io.delete_group("envsensors") diff --git a/examples/http/adafruit_io_metadata.py b/examples/http/adafruit_io_metadata.py index 2b0c5f4..dcabe10 100644 --- a/examples/http/adafruit_io_metadata.py +++ b/examples/http/adafruit_io_metadata.py @@ -34,37 +34,36 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards +status_light = neopixel.NeoPixel( + board.NEOPIXEL, 1, brightness=0.2 +) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" -#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) -aio_username = secrets['aio_username'] -aio_key = secrets['aio_key'] +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(aio_username, aio_key, wifi) try: # Get the 'location' feed from Adafruit IO - location_feed = io.get_feed('location') + location_feed = io.get_feed("location") except AdafruitIO_RequestError: # If no 'location' feed exists, create one - location_feed = io.create_new_feed('location') + location_feed = io.create_new_feed("location") # Set data data_value = 42 # Set up metadata associated with data_value -metadata = {'lat': 40.726190, - 'lon': -74.005334, - 'ele': -6, - 'created_at': None} +metadata = {"lat": 40.726190, "lon": -74.005334, "ele": -6, "created_at": None} # Send data and location metadata to the 'location' feed -print('Sending data and location metadata to IO...') -io.send_data(location_feed['key'], data_value, metadata) -print('Data sent!') +print("Sending data and location metadata to IO...") +io.send_data(location_feed["key"], data_value, metadata) +print("Data sent!") diff --git a/examples/http/adafruit_io_randomizer.py b/examples/http/adafruit_io_randomizer.py index 2717a18..b2889ed 100644 --- a/examples/http/adafruit_io_randomizer.py +++ b/examples/http/adafruit_io_randomizer.py @@ -35,16 +35,18 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards +status_light = neopixel.NeoPixel( + board.NEOPIXEL, 1, brightness=0.2 +) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" -#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) -aio_username = secrets['aio_username'] -aio_key = secrets['aio_key'] +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(aio_username, aio_key, wifi) @@ -57,11 +59,11 @@ while True: try: - print('Fetching random data from Adafruit IO...') + print("Fetching random data from Adafruit IO...") random_data = io.receive_random_data(random_data_id) - print('Random Data: ', random_data['value']) - print('Data Seed: ', random_data['seed']) - print('Waiting 1 minute to fetch new randomized data...') + print("Random Data: ", random_data["value"]) + print("Data Seed: ", random_data["seed"]) + print("Waiting 1 minute to fetch new randomized data...") except (ValueError, RuntimeError) as e: print("Failed to get data, retrying\n", e) wifi.reset() diff --git a/examples/http/adafruit_io_simpletest.py b/examples/http/adafruit_io_simpletest.py index eaa9277..a347757 100644 --- a/examples/http/adafruit_io_simpletest.py +++ b/examples/http/adafruit_io_simpletest.py @@ -34,34 +34,36 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards +status_light = neopixel.NeoPixel( + board.NEOPIXEL, 1, brightness=0.2 +) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" -#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) -aio_username = secrets['aio_username'] -aio_key = secrets['aio_key'] +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(aio_username, aio_key, wifi) try: # Get the 'temperature' feed from Adafruit IO - temperature_feed = io.get_feed('temperature') + temperature_feed = io.get_feed("temperature") except AdafruitIO_RequestError: # If no 'temperature' feed exists, create one - temperature_feed = io.create_new_feed('temperature') + temperature_feed = io.create_new_feed("temperature") # Send random integer values to the feed random_value = randint(0, 50) -print('Sending {0} to temperature feed...'.format(random_value)) -io.send_data(temperature_feed['key'], random_value) -print('Data sent!') +print("Sending {0} to temperature feed...".format(random_value)) +io.send_data(temperature_feed["key"], random_value) +print("Data sent!") # Retrieve data value from the feed -print('Retrieving data from temperature feed...') -received_data = io.receive_data(temperature_feed['key']) -print('Data from temperature feed: ', received_data['value']) +print("Retrieving data from temperature feed...") +received_data = io.receive_data(temperature_feed["key"]) +print("Data from temperature feed: ", received_data["value"]) diff --git a/examples/http/adafruit_io_temperature.py b/examples/http/adafruit_io_temperature.py index d5085cc..020e54c 100644 --- a/examples/http/adafruit_io_temperature.py +++ b/examples/http/adafruit_io_temperature.py @@ -42,26 +42,28 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards +status_light = neopixel.NeoPixel( + board.NEOPIXEL, 1, brightness=0.2 +) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" -#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) -aio_username = secrets['aio_username'] -aio_key = secrets['aio_key'] +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(aio_username, aio_key, wifi) try: # Get the 'temperature' feed from Adafruit IO - temperature_feed = io.get_feed('temperature') + temperature_feed = io.get_feed("temperature") except AdafruitIO_RequestError: # If no 'temperature' feed exists, create one - temperature_feed = io.create_new_feed('temperature') + temperature_feed = io.create_new_feed("temperature") # Set up ADT7410 sensor i2c_bus = busio.I2C(board.SCL, board.SDA) @@ -72,12 +74,12 @@ try: temperature = adt.temperature # set temperature value to two precision points - temperature = '%0.2f'%(temperature) + temperature = "%0.2f" % (temperature) - print('Current Temperature: {0}*C'.format(temperature)) - print('Sending to Adafruit IO...') - io.send_data(temperature_feed['key'], temperature) - print('Data sent!') + print("Current Temperature: {0}*C".format(temperature)) + print("Sending to Adafruit IO...") + io.send_data(temperature_feed["key"], temperature) + print("Data sent!") except (ValueError, RuntimeError) as e: print("Failed to get data, retrying\n", e) wifi.reset() diff --git a/examples/http/adafruit_io_weather.py b/examples/http/adafruit_io_weather.py index 3182584..33fc0f4 100644 --- a/examples/http/adafruit_io_weather.py +++ b/examples/http/adafruit_io_weather.py @@ -36,16 +36,18 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards +status_light = neopixel.NeoPixel( + board.NEOPIXEL, 1, brightness=0.2 +) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" -#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) # Set your Adafruit IO Username and Key in secrets.py # (visit io.adafruit.com if you need to create an account, # or if you need your Adafruit IO key.) -aio_username = secrets['aio_username'] -aio_key = secrets['aio_key'] +aio_username = secrets["aio_username"] +aio_key = secrets["aio_key"] # Create an instance of the Adafruit IO HTTP client io = IO_HTTP(aio_username, aio_key, wifi) @@ -56,18 +58,25 @@ # and copy over the location ID) location_id = 1234 -print('Getting weather record from IO...') +print("Getting weather record from IO...") # Get the specified weather record with current weather # and all available forecast information. forecast = io.receive_weather(location_id) # Get today's forecast -current_forecast = forecast['current'] -print('It is {0} and {1}*F.'.format(current_forecast['summary'], current_forecast['temperature'])) -print('with a humidity of {0}%'.format(current_forecast['humidity'] * 100)) +current_forecast = forecast["current"] +print( + "It is {0} and {1}*F.".format( + current_forecast["summary"], current_forecast["temperature"] + ) +) +print("with a humidity of {0}%".format(current_forecast["humidity"] * 100)) # Get tomorrow's forecast -tom_forecast = forecast['forecast_days_1'] -print('\nTomorrow has a low of {0}*F and a high of {1}*F.'.format( - tom_forecast['temperatureLow'], tom_forecast['temperatureHigh'])) -print('with a humidity of {0}%'.format(tom_forecast['humidity'] * 100)) +tom_forecast = forecast["forecast_days_1"] +print( + "\nTomorrow has a low of {0}*F and a high of {1}*F.".format( + tom_forecast["temperatureLow"], tom_forecast["temperatureHigh"] + ) +) +print("with a humidity of {0}%".format(tom_forecast["humidity"] * 100)) diff --git a/examples/mqtt/adafruit_io_groups.py b/examples/mqtt/adafruit_io_groups.py index a1a567a..5297393 100755 --- a/examples/mqtt/adafruit_io_groups.py +++ b/examples/mqtt/adafruit_io_groups.py @@ -5,10 +5,10 @@ import board import busio +from digitalio import DigitalInOut from adafruit_esp32spi import adafruit_esp32spi from adafruit_esp32spi import adafruit_esp32spi_wifimanager import adafruit_esp32spi.adafruit_esp32spi_socket as socket -from digitalio import DigitalInOut import neopixel from adafruit_io.adafruit_io import IO_MQTT from adafruit_minimqtt import MQTT @@ -62,11 +62,13 @@ def connected(client): # Subscribe to Group io.subscribe(group_key=group_name) + # pylint: disable=unused-argument def disconnected(client): # Disconnected function will be called when the client disconnects. print("Disconnected from Adafruit IO!") + # pylint: disable=unused-argument def message(client, feed_id, payload): # Message function will be called when a subscribed feed has a new value. @@ -84,7 +86,7 @@ def message(client, feed_id, payload): broker="io.adafruit.com", username=secrets["aio_user"], password=secrets["aio_key"], - network_manager=wifi + network_manager=wifi, ) # Initialize an Adafruit IO MQTT Client diff --git a/examples/mqtt/adafruit_io_location.py b/examples/mqtt/adafruit_io_location.py index 76c0a07..4f9700a 100755 --- a/examples/mqtt/adafruit_io_location.py +++ b/examples/mqtt/adafruit_io_location.py @@ -61,11 +61,13 @@ def connected(client): # Subscribe to a feed named location io.subscribe("location") + # pylint: disable=unused-argument def disconnected(client): # Disconnected function will be called when the client disconnects. print("Disconnected from Adafruit IO!") + # pylint: disable=unused-argument def message(client, feed_id, payload): # Message function will be called when a subscribed feed has a new value. @@ -83,7 +85,7 @@ def message(client, feed_id, payload): broker="io.adafruit.com", username=secrets["aio_user"], password=secrets["aio_key"], - network_manager=wifi + network_manager=wifi, ) # Initialize an Adafruit IO MQTT Client diff --git a/examples/mqtt/adafruit_io_simpletest.py b/examples/mqtt/adafruit_io_simpletest.py index dd60703..56326ee 100755 --- a/examples/mqtt/adafruit_io_simpletest.py +++ b/examples/mqtt/adafruit_io_simpletest.py @@ -10,10 +10,10 @@ import board import busio +from digitalio import DigitalInOut from adafruit_esp32spi import adafruit_esp32spi from adafruit_esp32spi import adafruit_esp32spi_wifimanager import adafruit_esp32spi.adafruit_esp32spi_socket as socket -from digitalio import DigitalInOut import neopixel from adafruit_io.adafruit_io import IO_MQTT from adafruit_minimqtt import MQTT @@ -65,19 +65,23 @@ def connected(client): # Subscribe to changes on a feed named DemoFeed. client.subscribe("DemoFeed") + def subscribe(client, userdata, topic, granted_qos): # This method is called when the client subscribes to a new feed. - print('Subscribed to {0} with QOS level {1}'.format(topic, granted_qos)) + print("Subscribed to {0} with QOS level {1}".format(topic, granted_qos)) + def unsubscribe(client, userdata, topic, pid): # This method is called when the client unsubscribes from a feed. - print('Unsubscribed from {0} with PID {1}'.format(topic, pid)) + print("Unsubscribed from {0} with PID {1}".format(topic, pid)) + # pylint: disable=unused-argument def disconnected(client): # Disconnected function will be called when the client disconnects. print("Disconnected from Adafruit IO!") + # pylint: disable=unused-argument def message(client, feed_id, payload): # Message function will be called when a subscribed feed has a new value. @@ -95,7 +99,7 @@ def message(client, feed_id, payload): broker="io.adafruit.com", username=secrets["aio_user"], password=secrets["aio_key"], - network_manager=wifi + network_manager=wifi, ) # Initialize an Adafruit IO MQTT Client diff --git a/examples/mqtt/adafruit_io_time.py b/examples/mqtt/adafruit_io_time.py index a07b117..4af325a 100755 --- a/examples/mqtt/adafruit_io_time.py +++ b/examples/mqtt/adafruit_io_time.py @@ -60,26 +60,28 @@ def connected(client): # Subscribe to time/seconds topic # https://io.adafruit.com/api/docs/mqtt.html#time-seconds - io.subscribe_to_time('seconds') + io.subscribe_to_time("seconds") # Subscribe to time/millis topic # https://io.adafruit.com/api/docs/mqtt.html#time-millis - io.subscribe_to_time('millis') + io.subscribe_to_time("millis") # Subscribe to time/ISO-8601 topic # https://io.adafruit.com/api/docs/mqtt.html#time-iso-8601 - io.subscribe_to_time('iso') + io.subscribe_to_time("iso") # Subscribe to time/hours topic # NOTE: This topic only publishes once every hour. # https://io.adafruit.com/api/docs/mqtt.html#adafruit-io-monitor - io.subscribe_to_time('hours') + io.subscribe_to_time("hours") + # pylint: disable=unused-argument def disconnected(client): # Disconnected function will be called when the client disconnects. print("Disconnected from Adafruit IO!") + # pylint: disable=unused-argument def message(client, feed_id, payload): # Message function will be called when a subscribed feed has a new value. diff --git a/setup.py b/setup.py index 88e6d11..aeaf722 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ """ from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -13,51 +14,39 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-adafruitio', - + name="adafruit-circuitpython-adafruitio", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='Adafruit IO for CircuitPython', + setup_requires=["setuptools_scm"], + description="Adafruit IO for CircuitPython", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO', - + url="https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=[ - 'Adafruit-Blinka', - 'Adafruit_CircuitPython_ESP32SPI' - ], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka", "Adafruit_CircuitPython_ESP32SPI"], # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit blinka circuitpython micropython adafruit_io adafruit-io rest api iot ' - 'wifi', - + keywords="adafruit blinka circuitpython micropython adafruit_io adafruit-io rest api iot " + "wifi", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=['adafruit_adafruit_io'], + py_modules=["adafruit_adafruit_io"], )