diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 33c2a61..88bca9f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,9 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: os: ubuntu-20.04 tools: diff --git a/README.rst b/README.rst index 66eab38..462506b 100644 --- a/README.rst +++ b/README.rst @@ -25,6 +25,8 @@ Dependencies This driver depends on: * `Adafruit CircuitPython `_ +* `Adafruit CircuitPython Connection Manager `_ +* `Adafruit CircuitPython Requests `_ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading diff --git a/docs/conf.py b/docs/conf.py index 1c783de..48c80a9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -110,19 +110,9 @@ # 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" - -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(), "."] - except: - html_theme = "default" - html_theme_path = ["."] -else: - html_theme_path = ["."] +import sphinx_rtd_theme + +html_theme = "sphinx_rtd_theme" # 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, diff --git a/docs/requirements.txt b/docs/requirements.txt index 797aa04..979f568 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,6 @@ # # SPDX-License-Identifier: Unlicense -sphinx>=4.0.0 +sphinx sphinxcontrib-jquery +sphinx-rtd-theme diff --git a/examples/oauth2_simpletest.py b/examples/oauth2_simpletest.py index c1c6881..878b83e 100644 --- a/examples/oauth2_simpletest.py +++ b/examples/oauth2_simpletest.py @@ -1,25 +1,23 @@ # SPDX-FileCopyrightText: 2020 Brent Rubell, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense + +from os import getenv import ssl import wifi import socketpool import adafruit_requests from adafruit_oauth2 import OAuth2 -# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and -# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other -# source control. -# pylint: disable=no-name-in-module,wrong-import-order -try: - from secrets import secrets -except ImportError: - print("Credentials and tokens are kept in secrets.py, please add them there!") - raise +# Get WiFi details and Google keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +google_client_id = getenv("google_client_id") +google_client_secret = getenv("google_client_secret") -print("Connecting to %s" % secrets["ssid"]) -wifi.radio.connect(secrets["ssid"], secrets["password"]) -print("Connected to %s!" % secrets["ssid"]) +print(f"Connecting to {ssid}") +wifi.radio.connect(ssid, password) +print(f"Connected to {ssid}") pool = socketpool.SocketPool(wifi.radio) requests = adafruit_requests.Session(pool, ssl.create_default_context()) @@ -29,9 +27,7 @@ scopes = ["email"] # Initialize an OAuth2 object -google_auth = OAuth2( - requests, secrets["google_client_id"], secrets["google_client_secret"], scopes -) +google_auth = OAuth2(requests, google_client_id, google_client_secret, scopes) # Request device and user codes # https://developers.google.com/identity/protocols/oauth2/limited-input-device#step-1:-request-device-and-user-codes diff --git a/examples/oauth2_simpletest_cpython.py b/examples/oauth2_simpletest_cpython.py index cd3a43b..3fa8025 100644 --- a/examples/oauth2_simpletest_cpython.py +++ b/examples/oauth2_simpletest_cpython.py @@ -1,20 +1,16 @@ # SPDX-FileCopyrightText: 2020 Brent Rubell, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense + +from os import getenv import socket import ssl import adafruit_requests from adafruit_oauth2 import OAuth2 -# Add a secrets.py to your filesystem that has a dictionary called secrets with Google -# application tokens. DO NOT share that file or commit it into Git or other -# source control. -# pylint: disable=no-name-in-module,wrong-import-order -try: - from secrets import secrets -except ImportError: - print("Credentials and tokens are kept in secrets.py, please add them there!") - raise +# Get Google keys, ensure these are setup in settings.toml +google_client_id = getenv("google_client_id") +google_client_secret = getenv("google_client_secret") requests = adafruit_requests.Session(socket, ssl.create_default_context()) @@ -22,9 +18,7 @@ scopes = ["email"] # Initialize an OAuth2 object -google_auth = OAuth2( - requests, secrets["google_client_id"], secrets["google_client_secret"], scopes -) +google_auth = OAuth2(requests, google_client_id, google_client_secret, scopes) # Request device and user codes # https://developers.google.com/identity/protocols/oauth2/limited-input-device#step-1:-request-device-and-user-codes diff --git a/examples/oauth2_simpletest_esp32spi.py b/examples/oauth2_simpletest_esp32spi.py index 404feae..1428acc 100644 --- a/examples/oauth2_simpletest_esp32spi.py +++ b/examples/oauth2_simpletest_esp32spi.py @@ -1,24 +1,22 @@ # SPDX-FileCopyrightText: 2020 Brent Rubell, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense + +from os import getenv import board import busio from digitalio import DigitalInOut -import adafruit_esp32spi.adafruit_esp32spi_socket as socket +import adafruit_connection_manager from adafruit_esp32spi import adafruit_esp32spi -import adafruit_requests as requests +import adafruit_requests from adafruit_oauth2 import OAuth2 -# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and -# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other -# source control. -# pylint: disable=no-name-in-module,wrong-import-order -try: - from secrets import secrets -except ImportError: - print("Credentials and tokens are kept in secrets.py, please add them there!") - raise +# Get WiFi details and Google keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +google_client_id = getenv("google_client_id") +google_client_secret = getenv("google_client_secret") esp32_cs = DigitalInOut(board.ESP_CS) esp32_ready = DigitalInOut(board.ESP_BUSY) @@ -30,23 +28,22 @@ print("Connecting to AP...") while not esp.is_connected: try: - esp.connect_AP(secrets["ssid"], secrets["password"]) + esp.connect_AP(ssid, password) except RuntimeError as e: print("could not connect to AP, retrying: ", e) continue print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) -# Initialize a requests object -socket.set_interface(esp) -requests.set_socket(socket, esp) +# Initialize a requests session +pool = adafruit_connection_manager.get_radio_socketpool(esp) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) +requests = adafruit_requests.Session(pool, ssl_context) # Set scope(s) of access required by the API you're using scopes = ["email"] # Initialize an OAuth2 object -google_auth = OAuth2( - requests, secrets["google_client_id"], secrets["google_client_secret"], scopes -) +google_auth = OAuth2(requests, google_client_id, google_client_secret, scopes) # Request device and user codes # https://developers.google.com/identity/protocols/oauth2/limited-input-device#step-1:-request-device-and-user-codes