From 2f6562f9a3a0b84eb3f387ccc5dd9ed72f2c59b0 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 1/7] remove deprecated get_html_theme_path() call Signed-off-by: foamyguy --- docs/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 33bdb2d..4bd1f17 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -109,7 +109,6 @@ import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_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, From 24b9f950a02556e0cc492270a30c680d76875ecb Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 2/7] add sphinx configuration to rtd.yaml Signed-off-by: foamyguy --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) 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: From 028300fcb46a7dda55a3184e69019b940de81c0d Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Mon, 24 Feb 2025 13:54:22 -0800 Subject: [PATCH 3/7] Remove secrets usage --- README.rst | 27 +++++++------ .../azureiot_central_commands.py | 31 +++++++------- .../azureiot_central_notconnected.py | 31 +++++++------- .../azureiot_central_properties.py | 31 +++++++------- .../azureiot_central_simpletest.py | 31 +++++++------- .../azureiot_hub_directmethods.py | 25 ++++++------ .../azureiot_hub_messages.py | 25 ++++++------ .../azureiot_hub_simpletest.py | 25 ++++++------ .../azureiot_hub_twin_operations.py | 25 ++++++------ .../azureiot_central_commands.py | 23 ++++++----- .../azureiot_central_notconnected.py | 23 ++++++----- .../azureiot_central_properties.py | 23 ++++++----- .../azureiot_central_simpletest.py | 25 ++++++------ .../azureiot_hub_directmethods.py | 19 +++++---- .../azureiot_hub_messages.py | 19 +++++---- .../azureiot_hub_simpletest.py | 19 +++++---- .../azureiot_hub_twin_operations.py | 19 +++++---- examples/azureiot_secrets_example.py | 40 ------------------- examples/azureiot_settings_example.py | 38 ++++++++++++++++++ 19 files changed, 257 insertions(+), 242 deletions(-) delete mode 100644 examples/azureiot_secrets_example.py create mode 100644 examples/azureiot_settings_example.py diff --git a/README.rst b/README.rst index 1052c4d..95c1385 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ To interact with Azure IoT Hub, you will need to create a hub, and a register a - Open the `Azure Portal `_. - Follow the instructions in `Microsoft Docs `_ to create an Azure IoT Hub and register a device. -- Copy the devices Primary or secondary connection string, and add this to your ``secrets.py`` file. +- Copy the devices Primary or secondary connection string, and add this to your ``settings.toml`` file. You can find the device connection string by selecting the IoT Hub in the `Azure Portal `_, *selecting Explorer -> IoT devices*, then selecting your device. @@ -128,7 +128,7 @@ Then copy either the primary or secondary connection string using the copy butto from adafruit_azureiot import IoTHubDevice - device = IoTHubDevice(wifi, secrets["device_connection_string"]) + device = IoTHubDevice(wifi, device_connection_string) device.connect() Once the device is connected, you will regularly need to run a ``loop`` to poll for messages from the cloud. @@ -197,7 +197,7 @@ To use Azure IoT Central, you will need to create an Azure IoT Central app, crea - Head to `Azure IoT Central `__ - Follow the instructions in the `Microsoft Docs `__ to create an application. Every tier is free for up to 2 devices. - Follow the instructions in the `Microsoft Docs `__ to create a device template. -- Create a device based off the template, and select **Connect** to get the device connection details. Store the ID Scope, Device ID and either the primary or secondary device SAS key in your ``secrets.py`` file. +- Create a device based off the template, and select **Connect** to get the device connection details. Store the ID Scope, Device ID and either the primary or secondary device SAS key in your ``settings.toml`` file. .. image:: iot-central-connect-button.png :alt: The IoT Central connect button @@ -209,18 +209,19 @@ To use Azure IoT Central, you will need to create an Azure IoT Central app, crea *The connection details dialog* + +settings.toml: + .. code-block:: python - secrets = { - # WiFi settings - "ssid": "", - "password": "", + # WiFi settings + CIRCUITPY_WIFI_SSID="", + CIRCUITPY_WIFI_PASSWORD="", - # Azure IoT Central settings - "id_scope": "", - "device_id": "", - "device_sas_key": "" - } + # Azure IoT Central settings + id_scope="" + device_id="" + device_sas_key="" **Connect your device to your Azure IoT Central app** @@ -228,7 +229,7 @@ To use Azure IoT Central, you will need to create an Azure IoT Central app, crea from adafruit_azureiot import IoTCentralDevice - device = IoTCentralDevice(wifi, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"]) + device = IoTCentralDevice(wifi, id_scope, device_id, device_sas_key) device.connect() Once the device is connected, you will regularly need to run a ``loop`` to poll for messages from the cloud. diff --git a/examples/azureiot_esp32spi/azureiot_central_commands.py b/examples/azureiot_esp32spi/azureiot_central_commands.py index d11cc1f..d0922e0 100644 --- a/examples/azureiot_esp32spi/azureiot_central_commands.py +++ b/examples/azureiot_esp32spi/azureiot_central_commands.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import time import board import busio @@ -10,12 +11,12 @@ from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager import adafruit_connection_manager -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and AWS Keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +id_scope = getenv("id_scope") +device_id = getenv("device_id") +device_sas_key = getenv("device_sas_key") # ESP32 Setup try: @@ -31,19 +32,21 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel( +status_pixel = 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_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +wifi = adafruit_esp32spi_wifimanager.WiFiManager( + esp, ssid, password, status_pixel=status_pixel +) print("Connecting to WiFi...") @@ -86,7 +89,7 @@ # # Next create a device using the device template, and select Connect to get the device connection # details. -# Add the connection details to your secrets.py file, using the following values: +# Add the connection details to your settings.toml file, using the following values: # # 'id_scope' - the devices ID scope # 'device_id' - the devices device id @@ -108,9 +111,9 @@ device = IoTCentralDevice( pool, ssl_context, - secrets["id_scope"], - secrets["device_id"], - secrets["device_sas_key"], + id_scope, + device_id, + device_sas_key, ) diff --git a/examples/azureiot_esp32spi/azureiot_central_notconnected.py b/examples/azureiot_esp32spi/azureiot_central_notconnected.py index 8cb7863..b03ab46 100644 --- a/examples/azureiot_esp32spi/azureiot_central_notconnected.py +++ b/examples/azureiot_esp32spi/azureiot_central_notconnected.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import json import random import time @@ -12,12 +13,12 @@ from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager import adafruit_connection_manager -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and AWS Keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +id_scope = getenv("id_scope") +device_id = getenv("device_id") +device_sas_key = getenv("device_sas_key") # ESP32 Setup try: @@ -33,19 +34,21 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel( +status_pixel = 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_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +wifi = adafruit_esp32spi_wifimanager.WiFiManager( + esp, ssid, password, status_pixel=status_pixel +) print("Connecting to WiFi...") @@ -80,7 +83,7 @@ # # Next create a device using the device template, and select Connect to get the device connection # details. -# Add the connection details to your secrets.py file, using the following values: +# Add the connection details to your settings.toml file, using the following values: # # 'id_scope' - the devices ID scope # 'device_id' - the devices device id @@ -104,9 +107,9 @@ device = IoTCentralDevice( pool, ssl_context, - secrets["id_scope"], - secrets["device_id"], - secrets["device_sas_key"], + id_scope, + device_id, + device_sas_key, ) # don't connect diff --git a/examples/azureiot_esp32spi/azureiot_central_properties.py b/examples/azureiot_esp32spi/azureiot_central_properties.py index 43d131b..bb8d208 100644 --- a/examples/azureiot_esp32spi/azureiot_central_properties.py +++ b/examples/azureiot_esp32spi/azureiot_central_properties.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import random import time import board @@ -11,12 +12,12 @@ from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager import adafruit_connection_manager -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and AWS Keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +id_scope = getenv("id_scope") +device_id = getenv("device_id") +device_sas_key = getenv("device_sas_key") # ESP32 Setup try: @@ -32,19 +33,21 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel( +status_pixel = 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_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +wifi = adafruit_esp32spi_wifimanager.WiFiManager( + esp, ssid, password, status_pixel=status_pixel +) print("Connecting to WiFi...") @@ -87,7 +90,7 @@ # # Next create a device using the device template, and select Connect to get the device connection # details. -# Add the connection details to your secrets.py file, using the following values: +# Add the connection details to your settings.toml file, using the following values: # # 'id_scope' - the devices ID scope # 'device_id' - the devices device id @@ -105,9 +108,9 @@ device = IoTCentralDevice( pool, ssl_context, - secrets["id_scope"], - secrets["device_id"], - secrets["device_sas_key"], + id_scope, + device_id, + device_sas_key, ) diff --git a/examples/azureiot_esp32spi/azureiot_central_simpletest.py b/examples/azureiot_esp32spi/azureiot_central_simpletest.py index ad66d2c..01faade 100644 --- a/examples/azureiot_esp32spi/azureiot_central_simpletest.py +++ b/examples/azureiot_esp32spi/azureiot_central_simpletest.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import json import random import time @@ -12,12 +13,12 @@ from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager import adafruit_connection_manager -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and AWS Keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +id_scope = getenv("id_scope") +device_id = getenv("device_id") +device_sas_key = getenv("device_sas_key") # ESP32 Setup try: @@ -33,19 +34,21 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel( +status_pixel = 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_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +wifi = adafruit_esp32spi_wifimanager.WiFiManager( + esp, ssid, password, status_pixel=status_pixel +) print("Connecting to WiFi...") @@ -88,7 +91,7 @@ # # Next create a device using the device template, and select Connect to get the device connection # details. -# Add the connection details to your secrets.py file, using the following values: +# Add the connection details to your settings.toml file, using the following values: # # 'id_scope' - the devices ID scope # 'device_id' - the devices device id @@ -106,9 +109,9 @@ device = IoTCentralDevice( pool, ssl_context, - secrets["id_scope"], - secrets["device_id"], - secrets["device_sas_key"], + id_scope, + device_id, + device_sas_key, ) print("Connecting to Azure IoT Central...") diff --git a/examples/azureiot_esp32spi/azureiot_hub_directmethods.py b/examples/azureiot_esp32spi/azureiot_hub_directmethods.py index b329c0e..17466e9 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_directmethods.py +++ b/examples/azureiot_esp32spi/azureiot_hub_directmethods.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import time import board import busio @@ -10,12 +11,10 @@ from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager import adafruit_connection_manager -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and Azure keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +device_connection_string = getenv("device_connection_string") # ESP32 Setup try: @@ -31,19 +30,21 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel( +status_pixel = 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_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +wifi = adafruit_esp32spi_wifimanager.WiFiManager( + esp, ssid, password, status_pixel=status_pixel +) print("Connecting to WiFi...") @@ -84,7 +85,7 @@ # if you are using the free tier # # Once you have a hub and a device, copy the device primary connection string. -# Add it to the secrets.py file in an entry called device_connection_string +# Add it to the settings.toml file in an entry called device_connection_string # # The adafruit-circuitpython-azureiot library depends on the following libraries: # @@ -99,7 +100,7 @@ pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, device_connection_string) # Subscribe to direct method calls diff --git a/examples/azureiot_esp32spi/azureiot_hub_messages.py b/examples/azureiot_esp32spi/azureiot_hub_messages.py index 956a3a8..f242be5 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_messages.py +++ b/examples/azureiot_esp32spi/azureiot_hub_messages.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import json import random import time @@ -12,12 +13,10 @@ from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager import adafruit_connection_manager -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and Azure keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +device_connection_string = getenv("device_connection_string") # ESP32 Setup try: @@ -33,19 +32,21 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel( +status_pixel = 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_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +wifi = adafruit_esp32spi_wifimanager.WiFiManager( + esp, ssid, password, status_pixel=status_pixel +) print("Connecting to WiFi...") @@ -86,7 +87,7 @@ # if you are using the free tier # # Once you have a hub and a device, copy the device primary connection string. -# Add it to the secrets.py file in an entry called device_connection_string +# Add it to the settings.toml file in an entry called device_connection_string # # The adafruit-circuitpython-azureiot library depends on the following libraries: # @@ -97,7 +98,7 @@ pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, device_connection_string) # Subscribe to cloud to device messages diff --git a/examples/azureiot_esp32spi/azureiot_hub_simpletest.py b/examples/azureiot_esp32spi/azureiot_hub_simpletest.py index 20d7136..f92247b 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_simpletest.py +++ b/examples/azureiot_esp32spi/azureiot_hub_simpletest.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import json import random import time @@ -12,12 +13,10 @@ from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager import adafruit_connection_manager -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and Azure keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +device_connection_string = getenv("device_connection_string") # ESP32 Setup try: @@ -33,19 +32,21 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel( +status_pixel = 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_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +wifi = adafruit_esp32spi_wifimanager.WiFiManager( + esp, ssid, password, status_pixel=status_pixel +) print("Connecting to WiFi...") @@ -86,7 +87,7 @@ # if you are using the free tier # # Once you have a hub and a device, copy the device primary connection string. -# Add it to the secrets.py file in an entry called device_connection_string +# Add it to the settings.toml file in an entry called device_connection_string # # The adafruit-circuitpython-azureiot library depends on the following libraries: # @@ -97,7 +98,7 @@ pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, device_connection_string) print("Connecting to Azure IoT Hub...") diff --git a/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py b/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py index 3ed7842..1f7cdac 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py +++ b/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import random import time import board @@ -11,12 +12,10 @@ from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager import adafruit_connection_manager -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and Azure keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +device_connection_string = getenv("device_connection_string") # ESP32 Setup try: @@ -32,19 +31,21 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel( +status_pixel = 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_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +wifi = adafruit_esp32spi_wifimanager.WiFiManager( + esp, ssid, password, status_pixel=status_pixel +) print("Connecting to WiFi...") @@ -85,7 +86,7 @@ # if you are using the free tier # # Once you have a hub and a device, copy the device primary connection string. -# Add it to the secrets.py file in an entry called device_connection_string +# Add it to the settings.toml file in an entry called device_connection_string # # To us twins, you will need either a free or standard tier IoT Hub. Basic tier doesn't # support twins @@ -99,7 +100,7 @@ pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, device_connection_string) # Subscribe to device twin desired property updates diff --git a/examples/azureiot_native_networking/azureiot_central_commands.py b/examples/azureiot_native_networking/azureiot_central_commands.py index 85b0476..3dea2ed 100644 --- a/examples/azureiot_native_networking/azureiot_central_commands.py +++ b/examples/azureiot_native_networking/azureiot_central_commands.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import time import rtc @@ -11,15 +12,15 @@ from adafruit_azureiot import IoTCentralDevice from adafruit_azureiot.iot_mqtt import IoTResponse -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and AWS Keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +id_scope = getenv("id_scope") +device_id = getenv("device_id") +device_sas_key = getenv("device_sas_key") print("Connecting to WiFi...") -wifi.radio.connect(secrets["ssid"], secrets["password"]) +wifi.radio.connect(ssid, password) pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) @@ -57,7 +58,7 @@ # # Next create a device using the device template, and select Connect to get the device connection # details. -# Add the connection details to your secrets.py file, using the following values: +# Add the connection details to your settings.toml file, using the following values: # # 'id_scope' - the devices ID scope # 'device_id' - the devices device id @@ -73,9 +74,9 @@ device = IoTCentralDevice( pool, ssl_context, - secrets["id_scope"], - secrets["device_id"], - secrets["device_sas_key"], + id_scope, + device_id, + device_sas_key, ) diff --git a/examples/azureiot_native_networking/azureiot_central_notconnected.py b/examples/azureiot_native_networking/azureiot_central_notconnected.py index b695dae..55a3c48 100644 --- a/examples/azureiot_native_networking/azureiot_central_notconnected.py +++ b/examples/azureiot_native_networking/azureiot_central_notconnected.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import json import random import time @@ -15,15 +16,15 @@ IoTError, ) -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and AWS Keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +id_scope = getenv("id_scope") +device_id = getenv("device_id") +device_sas_key = getenv("device_sas_key") print("Connecting to WiFi...") -wifi.radio.connect(secrets["ssid"], secrets["password"]) +wifi.radio.connect(ssid, password) pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) @@ -61,7 +62,7 @@ # # Next create a device using the device template, and select Connect to get the device connection # details. -# Add the connection details to your secrets.py file, using the following values: +# Add the connection details to your settings.toml file, using the following values: # # 'id_scope' - the devices ID scope # 'device_id' - the devices device id @@ -77,9 +78,9 @@ device = IoTCentralDevice( pool, ssl_context, - secrets["id_scope"], - secrets["device_id"], - secrets["device_sas_key"], + id_scope, + device_id, + device_sas_key, ) # don't connect diff --git a/examples/azureiot_native_networking/azureiot_central_properties.py b/examples/azureiot_native_networking/azureiot_central_properties.py index 7cbd9c0..3c49cec 100644 --- a/examples/azureiot_native_networking/azureiot_central_properties.py +++ b/examples/azureiot_native_networking/azureiot_central_properties.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import random import time @@ -11,15 +12,15 @@ import adafruit_ntp from adafruit_azureiot import IoTCentralDevice -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and AWS Keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +id_scope = getenv("id_scope") +device_id = getenv("device_id") +device_sas_key = getenv("device_sas_key") print("Connecting to WiFi...") -wifi.radio.connect(secrets["ssid"], secrets["password"]) +wifi.radio.connect(ssid, password) pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) @@ -57,7 +58,7 @@ # # Next create a device using the device template, and select Connect to get the device connection # details. -# Add the connection details to your secrets.py file, using the following values: +# Add the connection details to your settings.toml file, using the following values: # # 'id_scope' - the devices ID scope # 'device_id' - the devices device id @@ -73,9 +74,9 @@ device = IoTCentralDevice( pool, ssl_context, - secrets["id_scope"], - secrets["device_id"], - secrets["device_sas_key"], + id_scope, + device_id, + device_sas_key, ) diff --git a/examples/azureiot_native_networking/azureiot_central_simpletest.py b/examples/azureiot_native_networking/azureiot_central_simpletest.py index 8ce022d..018de9f 100644 --- a/examples/azureiot_native_networking/azureiot_central_simpletest.py +++ b/examples/azureiot_native_networking/azureiot_central_simpletest.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import json import random import time @@ -12,15 +13,15 @@ import adafruit_ntp from adafruit_azureiot import IoTCentralDevice -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and AWS Keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +id_scope = getenv("id_scope") +device_id = getenv("device_id") +device_sas_key = getenv("device_sas_key") print("Connecting to WiFi...") -wifi.radio.connect(secrets["ssid"], secrets["password"]) +wifi.radio.connect(ssid, password) pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) @@ -58,7 +59,7 @@ # # Next create a device using the device template, and select Connect to get the device connection # details. -# Add the connection details to your secrets.py file, using the following values: +# Add the connection details to your settings.toml file, using the following values: # # 'id_scope' - the devices ID scope # 'device_id' - the devices device id @@ -74,9 +75,9 @@ device = IoTCentralDevice( pool, ssl_context, - secrets["id_scope"], - secrets["device_id"], - secrets["device_sas_key"], + id_scope, + device_id, + device_sas_key, ) print("Connecting to Azure IoT Central...") @@ -103,7 +104,7 @@ print("Connection error, reconnecting\n", str(e)) wifi.radio.enabled = False wifi.radio.enabled = True - wifi.radio.connect(secrets["ssid"], secrets["password"]) + wifi.radio.connect(ssid, password) device.reconnect() continue time.sleep(1) diff --git a/examples/azureiot_native_networking/azureiot_hub_directmethods.py b/examples/azureiot_native_networking/azureiot_hub_directmethods.py index c0857f0..a61bb54 100644 --- a/examples/azureiot_native_networking/azureiot_hub_directmethods.py +++ b/examples/azureiot_native_networking/azureiot_hub_directmethods.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import time import rtc @@ -11,15 +12,13 @@ from adafruit_azureiot import IoTHubDevice from adafruit_azureiot.iot_mqtt import IoTResponse -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +device_connection_string = getenv("device_connection_string") print("Connecting to WiFi...") -wifi.radio.connect(secrets["ssid"], secrets["password"]) +wifi.radio.connect(ssid, password) pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) @@ -55,7 +54,7 @@ # if you are using the free tier # # Once you have a hub and a device, copy the device primary connection string. -# Add it to the secrets.py file in an entry called device_connection_string +# Add it to the settings.toml file in an entry called device_connection_string # # The adafruit-circuitpython-azureiot library depends on the following libraries: # @@ -64,7 +63,7 @@ # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, device_connection_string) # Subscribe to direct method calls @@ -96,7 +95,7 @@ def direct_method_invoked(method_name: str, payload) -> IoTResponse: # If we lose connectivity, reset the wifi and reconnect wifi.radio.enabled = False wifi.radio.enabled = True - wifi.radio.connect(secrets["ssid"], secrets["password"]) + wifi.radio.connect(ssid, password) device.reconnect() continue diff --git a/examples/azureiot_native_networking/azureiot_hub_messages.py b/examples/azureiot_native_networking/azureiot_hub_messages.py index cc9a57e..32dc3e1 100644 --- a/examples/azureiot_native_networking/azureiot_hub_messages.py +++ b/examples/azureiot_native_networking/azureiot_hub_messages.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import json import random import time @@ -12,15 +13,13 @@ import adafruit_ntp from adafruit_azureiot import IoTHubDevice -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and Azure keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +device_connection_string = getenv("device_connection_string") print("Connecting to WiFi...") -wifi.radio.connect(secrets["ssid"], secrets["password"]) +wifi.radio.connect(ssid, password) pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) @@ -56,7 +55,7 @@ # if you are using the free tier # # Once you have a hub and a device, copy the device primary connection string. -# Add it to the secrets.py file in an entry called device_connection_string +# Add it to the settings.toml file in an entry called device_connection_string # # The adafruit-circuitpython-azureiot library depends on the following libraries: # @@ -65,7 +64,7 @@ # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, device_connection_string) # Subscribe to cloud to device messages @@ -104,7 +103,7 @@ def cloud_to_device_message_received(body: str, properties: dict): # If we lose connectivity, reset the wifi and reconnect wifi.radio.enabled = False wifi.radio.enabled = True - wifi.radio.connect(secrets["ssid"], secrets["password"]) + wifi.radio.connect(ssid, password) device.reconnect() continue time.sleep(1) diff --git a/examples/azureiot_native_networking/azureiot_hub_simpletest.py b/examples/azureiot_native_networking/azureiot_hub_simpletest.py index 8da982d..1ebf496 100644 --- a/examples/azureiot_native_networking/azureiot_hub_simpletest.py +++ b/examples/azureiot_native_networking/azureiot_hub_simpletest.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import json import random import time @@ -12,15 +13,13 @@ import adafruit_ntp from adafruit_azureiot import IoTHubDevice -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and Azure keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +device_connection_string = getenv("device_connection_string") print("Connecting to WiFi...") -wifi.radio.connect(secrets["ssid"], secrets["password"]) +wifi.radio.connect(ssid, password) pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) @@ -56,7 +55,7 @@ # if you are using the free tier # # Once you have a hub and a device, copy the device primary connection string. -# Add it to the secrets.py file in an entry called device_connection_string +# Add it to the settings.toml file in an entry called device_connection_string # # The adafruit-circuitpython-azureiot library depends on the following libraries: # @@ -65,7 +64,7 @@ # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, device_connection_string) print("Connecting to Azure IoT Hub...") @@ -95,7 +94,7 @@ # If we lose connectivity, reset the wifi and reconnect wifi.radio.enabled = False wifi.radio.enabled = True - wifi.radio.connect(secrets["ssid"], secrets["password"]) + wifi.radio.connect(ssid, password) device.reconnect() continue time.sleep(1) diff --git a/examples/azureiot_native_networking/azureiot_hub_twin_operations.py b/examples/azureiot_native_networking/azureiot_hub_twin_operations.py index 90b3303..2bea634 100644 --- a/examples/azureiot_native_networking/azureiot_hub_twin_operations.py +++ b/examples/azureiot_native_networking/azureiot_hub_twin_operations.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import random import time @@ -11,15 +12,13 @@ import adafruit_ntp from adafruit_azureiot import IoTHubDevice -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details and Azure keys, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +device_connection_string = getenv("device_connection_string") print("Connecting to WiFi...") -wifi.radio.connect(secrets["ssid"], secrets["password"]) +wifi.radio.connect(ssid, password) pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) @@ -55,7 +54,7 @@ # if you are using the free tier # # Once you have a hub and a device, copy the device primary connection string. -# Add it to the secrets.py file in an entry called device_connection_string +# Add it to the settings.toml file in an entry called device_connection_string # # The adafruit-circuitpython-azureiot library depends on the following libraries: # @@ -64,7 +63,7 @@ # Create an IoT Hub device client and connect -device = IoTHubDevice(pool, ssl_context, secrets["device_connection_string"]) +device = IoTHubDevice(pool, ssl_context, device_connection_string) # Subscribe to device twin desired property updates @@ -113,7 +112,7 @@ def device_twin_desired_updated( # If we lose connectivity, reset the wifi and reconnect wifi.radio.enabled = False wifi.radio.enabled = True - wifi.radio.connect(secrets["ssid"], secrets["password"]) + wifi.radio.connect(ssid, password) device.reconnect() continue time.sleep(1) diff --git a/examples/azureiot_secrets_example.py b/examples/azureiot_secrets_example.py deleted file mode 100644 index 37e618c..0000000 --- a/examples/azureiot_secrets_example.py +++ /dev/null @@ -1,40 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# SPDX-License-Identifier: MIT - -# This file is where you keep secret settings, passwords, and tokens! -# If you put them in the code you risk committing that info or sharing it -# which would be not great. So, instead, keep it all in this one file and -# keep it a secret. - -# To find out how to hide any changes you make to this file from Git, check out -# this blog post: https://www.jimbobbennett.io/hiding-api-keys-from-git/ - -""" -Contains the secrets for your app including WiFi connection details. -DO NOT CHECK THIS INTO SOURCE CODE CONTROL!!!!11!!! -""" - -secrets = { - # WiFi settings - "ssid": "", - "password": "", - # Azure IoT Central settings - if you are connecting to Azure IoT Central, fill in these three - # values - # To get these values, select your device in Azure IoT Central, - # then select the Connect button - # A dialog will appear with these three values - # id_scope comes from the ID scope value - # device_id comes from the Device ID value - # key comes from either the Primary key or Secondary key - "id_scope": "", - "device_id": "", - "device_sas_key": "", - # Azure IoT Hub settings - if you are connecting to Azure IoT Hub, fill in this value - # To get this value, from the Azure Portal (https://aka.ms/AzurePortalHome), select your IoT - # Hub, then select Explorers -> IoT devices, select your device, then copy the entire primary - # or secondary connection string using the copy button next to the value and set this here. - # It will be in the format: - # HostName=.azure-devices.net;DeviceId=;SharedAccessKey= - # Note - you need the primary or secondary connection string, NOT the primary or secondary key - "device_connection_string": "", -} diff --git a/examples/azureiot_settings_example.py b/examples/azureiot_settings_example.py new file mode 100644 index 0000000..276e1cd --- /dev/null +++ b/examples/azureiot_settings_example.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +# This file is where you keep settings, passwords, and tokens! +# If you put them in the code you risk committing that info or sharing it +# which would be not great. So, instead, keep it all in this one file and +# keep it a private. + +# To find out how to hide any changes you make to this file from Git, check out +# this blog post: https://www.jimbobbennett.io/hiding-api-keys-from-git/ + +# Contains the passwords and tokens for your app including WiFi connection details. +# DO NOT CHECK THIS INTO SOURCE CODE CONTROL!!!!11!!! + +# WiFi settings +CIRCUITPY_WIFI_SSID = "" +CIRCUITPY_WIFI_PASSWORD = "" + +# Azure IoT Central settings - if you are connecting to Azure IoT Central, fill in these three +# values +# To get these values, select your device in Azure IoT Central, +# then select the Connect button +# A dialog will appear with these three values +# id_scope comes from the ID scope value +# device_id comes from the Device ID value +# key comes from either the Primary key or Secondary key +id_scope = "" +device_id = "" +device_sas_key = "" +# Azure IoT Hub settings - if you are connecting to Azure IoT Hub, fill in this value + +# To get this value, from the Azure Portal (https://aka.ms/AzurePortalHome), select your IoT +# Hub, then select Explorers -> IoT devices, select your device, then copy the entire primary +# or secondary connection string using the copy button next to the value and set this here. +# It will be in the format: +# HostName=.azure-devices.net;DeviceId=;SharedAccessKey= +# Note - you need the primary or secondary connection string, NOT the primary or secondary key +device_connection_string = "" From 3e4e3d8dd26dc96d948e76d040539e14c38ed92b Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Mon, 24 Feb 2025 18:46:50 -0800 Subject: [PATCH 4/7] Update README.rst Co-authored-by: Dan Halbert --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 95c1385..18ef5f6 100644 --- a/README.rst +++ b/README.rst @@ -215,8 +215,8 @@ settings.toml: .. code-block:: python # WiFi settings - CIRCUITPY_WIFI_SSID="", - CIRCUITPY_WIFI_PASSWORD="", + CIRCUITPY_WIFI_SSID="" + CIRCUITPY_WIFI_PASSWORD="" # Azure IoT Central settings id_scope="" From 99e1de59efb20d8794ae4ab7b9cea0922b244755 Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Mon, 24 Feb 2025 19:05:00 -0800 Subject: [PATCH 5/7] Update README --- README.rst | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 18ef5f6..10c2187 100644 --- a/README.rst +++ b/README.rst @@ -215,21 +215,34 @@ settings.toml: .. code-block:: python # WiFi settings - CIRCUITPY_WIFI_SSID="" - CIRCUITPY_WIFI_PASSWORD="" + CIRCUITPY_WIFI_SSID="Your WiFi ssid" + CIRCUITPY_WIFI_PASSWORD="Your WiFi password" # Azure IoT Central settings - id_scope="" - device_id="" - device_sas_key="" + id_scope="Your ID Scope" + device_id="Your Device ID" + device_sas_key="Your Primary Key" **Connect your device to your Azure IoT Central app** .. code-block:: python + import wifi + from os import getenv from adafruit_azureiot import IoTCentralDevice + import adafruit_connection_manager - device = IoTCentralDevice(wifi, id_scope, device_id, device_sas_key) + ssid = getenv("CIRCUITPY_WIFI_SSID") + password = getenv("CIRCUITPY_WIFI_PASSWORD") + id_scope = getenv("id_scope") + device_id = getenv("device_id") + device_sas_key = getenv("device_sas_key") + + wifi.radio.connect(ssid, password) + + pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) + + device = IoTCentralDevice(pool, id_scope, device_id, device_sas_key) device.connect() Once the device is connected, you will regularly need to run a ``loop`` to poll for messages from the cloud. From 5da92931ecb37a0b55ae6d6065e77e8ae9383216 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 15 May 2025 20:15:25 +0000 Subject: [PATCH 6/7] change to ruff --- .gitattributes | 11 + .pre-commit-config.yaml | 43 +- .pylintrc | 399 ------------------ README.rst | 6 +- adafruit_azureiot/base64.py | 4 +- adafruit_azureiot/device_registration.py | 24 +- adafruit_azureiot/hmac.py | 290 ++++--------- adafruit_azureiot/iot_mqtt.py | 82 +--- adafruit_azureiot/iotcentral_device.py | 14 +- adafruit_azureiot/iothub_device.py | 29 +- adafruit_azureiot/quote.py | 7 +- docs/api.rst | 3 + docs/conf.py | 8 +- .../azureiot_central_commands.py | 18 +- .../azureiot_central_notconnected.py | 18 +- .../azureiot_central_properties.py | 17 +- .../azureiot_central_simpletest.py | 17 +- .../azureiot_hub_directmethods.py | 18 +- .../azureiot_hub_messages.py | 17 +- .../azureiot_hub_simpletest.py | 17 +- .../azureiot_hub_twin_operations.py | 17 +- .../azureiot_central_commands.py | 6 +- .../azureiot_central_notconnected.py | 6 +- .../azureiot_central_properties.py | 6 +- .../azureiot_central_simpletest.py | 6 +- .../azureiot_hub_directmethods.py | 6 +- .../azureiot_hub_messages.py | 6 +- .../azureiot_hub_simpletest.py | 6 +- .../azureiot_hub_twin_operations.py | 6 +- ruff.toml | 107 +++++ 30 files changed, 327 insertions(+), 887 deletions(-) create mode 100644 .gitattributes delete mode 100644 .pylintrc create mode 100644 ruff.toml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..21c125c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +.py text eol=lf +.rst text eol=lf +.txt text eol=lf +.yaml text eol=lf +.toml text eol=lf +.license text eol=lf +.md text eol=lf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70ade69..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,42 +1,21 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries # # SPDX-License-Identifier: Unlicense repos: - - repo: https://github.com/python/black - rev: 23.3.0 - hooks: - - id: black - - repo: https://github.com/fsfe/reuse-tool - rev: v1.1.2 - hooks: - - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pycqa/pylint - rev: v2.17.4 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: pylint - name: pylint (library code) - types: [python] - args: - - --disable=consider-using-f-string - exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint - name: pylint (example code) - description: Run pylint rules on "examples/*.py" files - types: [python] - files: "^examples/" - args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint - name: pylint (test code) - description: Run pylint rules on "tests/*.py" files - types: [python] - files: "^tests/" - args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - id: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 + hooks: + - id: reuse diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index f945e92..0000000 --- a/.pylintrc +++ /dev/null @@ -1,399 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist= - -# Add files or directories to the ignore-list. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. The -# regex matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. -jobs=1 - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins=pylint.extensions.no_self_use - -# Pickle collected data for later comparisons. -persistent=yes - -# Specify a configuration file. -#rcfile= - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call -disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable= - - -[REPORTS] - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio).You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -# notes=FIXME,XXX,TODO -notes=FIXME,XXX - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules=board - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,future.builtins - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -# expected-line-ending-format= -expected-line-ending-format=LF - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=yes - -# Minimum lines number of a similarity. -min-similarity-lines=12 - - -[BASIC] - -# Regular expression matching correct argument names -argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct attribute names -attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -# class-rgx=[A-Z_][a-zA-Z0-9]+$ -class-rgx=[A-Z_][a-zA-Z0-9_]+$ - -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Regular expression matching correct function names -function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Good variable names which should always be accepted, separated by a comma -# good-names=i,j,k,ex,Run,_ -good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -property-classes=abc.abstractproperty - -# Regular expression matching correct variable names -variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - - -[IMPORTS] - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=5 - -# Maximum number of attributes for a class (see R0902). -# max-attributes=7 -max-attributes=11 - -# Maximum number of boolean expressions in a if statement -max-bool-expr=5 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of locals for function / method body -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of statements in function / method body -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=1 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=builtins.Exception diff --git a/README.rst b/README.rst index 10c2187..b2d4f0b 100644 --- a/README.rst +++ b/README.rst @@ -13,9 +13,9 @@ Adafruit_CircuitPython_AzureIoT :target: https://github.com/adafruit/Adafruit_CircuitPython_AzureIoT/actions/ :alt: Build Status -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code Style: Black +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json + :target: https://github.com/astral-sh/ruff + :alt: Code Style: Ruff A CircuitPython device library for `Microsoft Azure IoT Services `_ from a CircuitPython device. This library only supports key-base authentication, it currently doesn't support X.509 certificates. diff --git a/adafruit_azureiot/base64.py b/adafruit_azureiot/base64.py index 03f140b..c9f3941 100644 --- a/adafruit_azureiot/base64.py +++ b/adafruit_azureiot/base64.py @@ -30,9 +30,7 @@ def _bytes_from_decode_data(data: str): try: return data.encode("ascii") except Exception as exc: - raise ValueError( - "string argument should contain only ASCII characters" - ) from exc + raise ValueError("string argument should contain only ASCII characters") from exc def b64encode(toencode: bytes) -> bytes: diff --git a/adafruit_azureiot/device_registration.py b/adafruit_azureiot/device_registration.py index b4532a1..e2ecce1 100644 --- a/adafruit_azureiot/device_registration.py +++ b/adafruit_azureiot/device_registration.py @@ -17,12 +17,12 @@ import time import adafruit_logging as logging -from adafruit_logging import Logger import adafruit_minimqtt.adafruit_minimqtt as MQTT +from adafruit_logging import Logger from . import constants -from .quote import quote from .keys import compute_derived_symmetric_key +from .quote import quote class DeviceRegistrationError(Exception): @@ -41,7 +41,6 @@ class DeviceRegistration: to IoT Central over MQTT """ - # pylint: disable=R0913 def __init__( self, socket_pool, @@ -76,8 +75,6 @@ def __init__( self._socket_pool = socket_pool self._ssl_context = ssl_context - # pylint: disable=W0613 - # pylint: disable=C0103 def _on_connect(self, client, userdata, _, rc) -> None: self._logger.info( f"- device_registration :: _on_connect :: rc = {rc}, userdata = {userdata}" @@ -85,7 +82,6 @@ def _on_connect(self, client, userdata, _, rc) -> None: self._auth_response_received = True - # pylint: disable=W0613 def _handle_dps_update(self, client, topic: str, msg: str) -> None: self._logger.info(f"Received registration results on topic {topic} - {msg}") message = json.loads(msg) @@ -107,9 +103,7 @@ def _connect_to_mqtt(self) -> None: self._mqtt.connect() - self._logger.info( - " - device_registration :: connect :: created mqtt client. connecting.." - ) + self._logger.info(" - device_registration :: connect :: created mqtt client. connecting..") while not self._auth_response_received: self._mqtt.loop(2) @@ -122,9 +116,7 @@ def _connect_to_mqtt(self) -> None: raise DeviceRegistrationError("Cannot connect to MQTT") def _start_registration(self) -> None: - self._mqtt.add_topic_callback( - "$dps/registrations/res/#", self._handle_dps_update - ) + self._mqtt.add_topic_callback("$dps/registrations/res/#", self._handle_dps_update) self._mqtt.subscribe("$dps/registrations/res/#") message = json.dumps({"registrationId": self._device_id}) @@ -182,15 +174,11 @@ def register_device(self, expiry: int) -> str: + f"{constants.DPS_API_VERSION}" ) - # pylint: disable=C0103 sr = self._id_scope + "%2Fregistrations%2F" + self._device_id - sig_no_encode = compute_derived_symmetric_key( - self._device_sas_key, sr + "\n" + str(expiry) - ) + sig_no_encode = compute_derived_symmetric_key(self._device_sas_key, sr + "\n" + str(expiry)) sig_encoded = quote(sig_no_encode, "~()*!.'") auth_string = ( - f"SharedAccessSignature sr={sr}&sig={sig_encoded}&se={expiry}" - "&skn=registration" + f"SharedAccessSignature sr={sr}&sig={sig_encoded}&se={expiry}" "&skn=registration" ) self._mqtt = MQTT.MQTT( diff --git a/adafruit_azureiot/hmac.py b/adafruit_azureiot/hmac.py index df2512d..d30d35e 100644 --- a/adafruit_azureiot/hmac.py +++ b/adafruit_azureiot/hmac.py @@ -14,8 +14,6 @@ """ -# pylint: disable=C0103, W0108, R0915, C0116, C0115, unnecessary-lambda-assignment - try: from typing import Union except ImportError: @@ -65,12 +63,10 @@ def sha_init() -> dict: return sha_info -ROR = ( - lambda x, y: (((x & 0xFFFFFFFF) >> (y & 31)) | (x << (32 - (y & 31)))) & 0xFFFFFFFF -) +ROR = lambda x, y: (((x & 0xFFFFFFFF) >> (y & 31)) | (x << (32 - (y & 31)))) & 0xFFFFFFFF Ch = lambda x, y, z: (z ^ (x & (y ^ z))) Maj = lambda x, y, z: (((x | y) & z) | (x & y)) -S = lambda x, n: ROR(x, n) +S = ROR R = lambda x, n: (x & 0xFFFFFFFF) >> n Sigma0 = lambda x: (S(x, 2) ^ S(x, 13) ^ S(x, 22)) Sigma1 = lambda x: (S(x, 6) ^ S(x, 11) ^ S(x, 25)) @@ -83,18 +79,13 @@ def sha_transform(sha_info: dict) -> None: d = sha_info["data"] for i in range(0, 16): - W.append( - (d[4 * i] << 24) + (d[4 * i + 1] << 16) + (d[4 * i + 2] << 8) + d[4 * i + 3] - ) + W.append((d[4 * i] << 24) + (d[4 * i + 1] << 16) + (d[4 * i + 2] << 8) + d[4 * i + 3]) for i in range(16, 64): - W.append( - (Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16]) & 0xFFFFFFFF - ) + W.append((Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16]) & 0xFFFFFFFF) ss = sha_info["digest"][:] - # pylint: disable=too-many-arguments, line-too-long def RND(a, b, c, d, e, f, g, h, i, ki): # type: ignore[no-untyped-def] """Compress""" t0 = h + Sigma1(e) + Ch(e, f, g) + ki + W[i] @@ -103,198 +94,70 @@ def RND(a, b, c, d, e, f, g, h, i, ki): # type: ignore[no-untyped-def] h = t0 + t1 return d & 0xFFFFFFFF, h & 0xFFFFFFFF - ss[3], ss[7] = RND( - ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 0, 0x428A2F98 - ) - ss[2], ss[6] = RND( - ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 1, 0x71374491 - ) - ss[1], ss[5] = RND( - ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 2, 0xB5C0FBCF - ) - ss[0], ss[4] = RND( - ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 3, 0xE9B5DBA5 - ) - ss[7], ss[3] = RND( - ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 4, 0x3956C25B - ) - ss[6], ss[2] = RND( - ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 5, 0x59F111F1 - ) - ss[5], ss[1] = RND( - ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 6, 0x923F82A4 - ) - ss[4], ss[0] = RND( - ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 7, 0xAB1C5ED5 - ) - ss[3], ss[7] = RND( - ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 8, 0xD807AA98 - ) - ss[2], ss[6] = RND( - ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 9, 0x12835B01 - ) - ss[1], ss[5] = RND( - ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 10, 0x243185BE - ) - ss[0], ss[4] = RND( - ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 11, 0x550C7DC3 - ) - ss[7], ss[3] = RND( - ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 12, 0x72BE5D74 - ) - ss[6], ss[2] = RND( - ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 13, 0x80DEB1FE - ) - ss[5], ss[1] = RND( - ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 14, 0x9BDC06A7 - ) - ss[4], ss[0] = RND( - ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 15, 0xC19BF174 - ) - ss[3], ss[7] = RND( - ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 16, 0xE49B69C1 - ) - ss[2], ss[6] = RND( - ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 17, 0xEFBE4786 - ) - ss[1], ss[5] = RND( - ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 18, 0x0FC19DC6 - ) - ss[0], ss[4] = RND( - ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 19, 0x240CA1CC - ) - ss[7], ss[3] = RND( - ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 20, 0x2DE92C6F - ) - ss[6], ss[2] = RND( - ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 21, 0x4A7484AA - ) - ss[5], ss[1] = RND( - ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 22, 0x5CB0A9DC - ) - ss[4], ss[0] = RND( - ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 23, 0x76F988DA - ) - ss[3], ss[7] = RND( - ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 24, 0x983E5152 - ) - ss[2], ss[6] = RND( - ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 25, 0xA831C66D - ) - ss[1], ss[5] = RND( - ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 26, 0xB00327C8 - ) - ss[0], ss[4] = RND( - ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 27, 0xBF597FC7 - ) - ss[7], ss[3] = RND( - ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 28, 0xC6E00BF3 - ) - ss[6], ss[2] = RND( - ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 29, 0xD5A79147 - ) - ss[5], ss[1] = RND( - ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 30, 0x06CA6351 - ) - ss[4], ss[0] = RND( - ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 31, 0x14292967 - ) - ss[3], ss[7] = RND( - ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 32, 0x27B70A85 - ) - ss[2], ss[6] = RND( - ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 33, 0x2E1B2138 - ) - ss[1], ss[5] = RND( - ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 34, 0x4D2C6DFC - ) - ss[0], ss[4] = RND( - ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 35, 0x53380D13 - ) - ss[7], ss[3] = RND( - ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 36, 0x650A7354 - ) - ss[6], ss[2] = RND( - ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 37, 0x766A0ABB - ) - ss[5], ss[1] = RND( - ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 38, 0x81C2C92E - ) - ss[4], ss[0] = RND( - ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 39, 0x92722C85 - ) - ss[3], ss[7] = RND( - ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 40, 0xA2BFE8A1 - ) - ss[2], ss[6] = RND( - ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 41, 0xA81A664B - ) - ss[1], ss[5] = RND( - ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 42, 0xC24B8B70 - ) - ss[0], ss[4] = RND( - ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 43, 0xC76C51A3 - ) - ss[7], ss[3] = RND( - ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 44, 0xD192E819 - ) - ss[6], ss[2] = RND( - ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 45, 0xD6990624 - ) - ss[5], ss[1] = RND( - ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 46, 0xF40E3585 - ) - ss[4], ss[0] = RND( - ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 47, 0x106AA070 - ) - ss[3], ss[7] = RND( - ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 48, 0x19A4C116 - ) - ss[2], ss[6] = RND( - ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 49, 0x1E376C08 - ) - ss[1], ss[5] = RND( - ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 50, 0x2748774C - ) - ss[0], ss[4] = RND( - ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 51, 0x34B0BCB5 - ) - ss[7], ss[3] = RND( - ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 52, 0x391C0CB3 - ) - ss[6], ss[2] = RND( - ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 53, 0x4ED8AA4A - ) - ss[5], ss[1] = RND( - ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 54, 0x5B9CCA4F - ) - ss[4], ss[0] = RND( - ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 55, 0x682E6FF3 - ) - ss[3], ss[7] = RND( - ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 56, 0x748F82EE - ) - ss[2], ss[6] = RND( - ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 57, 0x78A5636F - ) - ss[1], ss[5] = RND( - ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 58, 0x84C87814 - ) - ss[0], ss[4] = RND( - ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 59, 0x8CC70208 - ) - ss[7], ss[3] = RND( - ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 60, 0x90BEFFFA - ) - ss[6], ss[2] = RND( - ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 61, 0xA4506CEB - ) - ss[5], ss[1] = RND( - ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 62, 0xBEF9A3F7 - ) - ss[4], ss[0] = RND( - ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 63, 0xC67178F2 - ) + ss[3], ss[7] = RND(ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 0, 0x428A2F98) + ss[2], ss[6] = RND(ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 1, 0x71374491) + ss[1], ss[5] = RND(ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 2, 0xB5C0FBCF) + ss[0], ss[4] = RND(ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 3, 0xE9B5DBA5) + ss[7], ss[3] = RND(ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 4, 0x3956C25B) + ss[6], ss[2] = RND(ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 5, 0x59F111F1) + ss[5], ss[1] = RND(ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 6, 0x923F82A4) + ss[4], ss[0] = RND(ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 7, 0xAB1C5ED5) + ss[3], ss[7] = RND(ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 8, 0xD807AA98) + ss[2], ss[6] = RND(ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 9, 0x12835B01) + ss[1], ss[5] = RND(ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 10, 0x243185BE) + ss[0], ss[4] = RND(ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 11, 0x550C7DC3) + ss[7], ss[3] = RND(ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 12, 0x72BE5D74) + ss[6], ss[2] = RND(ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 13, 0x80DEB1FE) + ss[5], ss[1] = RND(ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 14, 0x9BDC06A7) + ss[4], ss[0] = RND(ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 15, 0xC19BF174) + ss[3], ss[7] = RND(ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 16, 0xE49B69C1) + ss[2], ss[6] = RND(ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 17, 0xEFBE4786) + ss[1], ss[5] = RND(ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 18, 0x0FC19DC6) + ss[0], ss[4] = RND(ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 19, 0x240CA1CC) + ss[7], ss[3] = RND(ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 20, 0x2DE92C6F) + ss[6], ss[2] = RND(ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 21, 0x4A7484AA) + ss[5], ss[1] = RND(ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 22, 0x5CB0A9DC) + ss[4], ss[0] = RND(ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 23, 0x76F988DA) + ss[3], ss[7] = RND(ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 24, 0x983E5152) + ss[2], ss[6] = RND(ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 25, 0xA831C66D) + ss[1], ss[5] = RND(ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 26, 0xB00327C8) + ss[0], ss[4] = RND(ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 27, 0xBF597FC7) + ss[7], ss[3] = RND(ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 28, 0xC6E00BF3) + ss[6], ss[2] = RND(ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 29, 0xD5A79147) + ss[5], ss[1] = RND(ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 30, 0x06CA6351) + ss[4], ss[0] = RND(ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 31, 0x14292967) + ss[3], ss[7] = RND(ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 32, 0x27B70A85) + ss[2], ss[6] = RND(ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 33, 0x2E1B2138) + ss[1], ss[5] = RND(ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 34, 0x4D2C6DFC) + ss[0], ss[4] = RND(ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 35, 0x53380D13) + ss[7], ss[3] = RND(ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 36, 0x650A7354) + ss[6], ss[2] = RND(ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 37, 0x766A0ABB) + ss[5], ss[1] = RND(ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 38, 0x81C2C92E) + ss[4], ss[0] = RND(ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 39, 0x92722C85) + ss[3], ss[7] = RND(ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 40, 0xA2BFE8A1) + ss[2], ss[6] = RND(ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 41, 0xA81A664B) + ss[1], ss[5] = RND(ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 42, 0xC24B8B70) + ss[0], ss[4] = RND(ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 43, 0xC76C51A3) + ss[7], ss[3] = RND(ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 44, 0xD192E819) + ss[6], ss[2] = RND(ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 45, 0xD6990624) + ss[5], ss[1] = RND(ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 46, 0xF40E3585) + ss[4], ss[0] = RND(ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 47, 0x106AA070) + ss[3], ss[7] = RND(ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 48, 0x19A4C116) + ss[2], ss[6] = RND(ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 49, 0x1E376C08) + ss[1], ss[5] = RND(ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 50, 0x2748774C) + ss[0], ss[4] = RND(ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 51, 0x34B0BCB5) + ss[7], ss[3] = RND(ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 52, 0x391C0CB3) + ss[6], ss[2] = RND(ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 53, 0x4ED8AA4A) + ss[5], ss[1] = RND(ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 54, 0x5B9CCA4F) + ss[4], ss[0] = RND(ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 55, 0x682E6FF3) + ss[3], ss[7] = RND(ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], 56, 0x748F82EE) + ss[2], ss[6] = RND(ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], 57, 0x78A5636F) + ss[1], ss[5] = RND(ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], 58, 0x84C87814) + ss[0], ss[4] = RND(ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], ss[4], 59, 0x8CC70208) + ss[7], ss[3] = RND(ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], ss[3], 60, 0x90BEFFFA) + ss[6], ss[2] = RND(ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], ss[2], 61, 0xA4506CEB) + ss[5], ss[1] = RND(ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], ss[1], 62, 0xBEF9A3F7) + ss[4], ss[0] = RND(ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], ss[0], 63, 0xC67178F2) # Feedback dig = [] @@ -382,13 +245,10 @@ def sha_final(sha_info: dict) -> bytes: dig = [] for i in sha_info["digest"]: - dig.extend( - [((i >> 24) & 0xFF), ((i >> 16) & 0xFF), ((i >> 8) & 0xFF), (i & 0xFF)] - ) + dig.extend([((i >> 24) & 0xFF), ((i >> 16) & 0xFF), ((i >> 8) & 0xFF), (i & 0xFF)]) return bytes(dig) -# pylint: disable=protected-access class sha256: digest_size = digestsize = SHA_DIGESTSIZE block_size = SHA_BLOCKSIZE @@ -430,9 +290,7 @@ class HMAC: blocksize = 64 # 512-bit HMAC; can be changed in subclasses. - def __init__( - self, key: Union[bytes, bytearray], msg: Union[bytes, bytearray] = None - ): + def __init__(self, key: Union[bytes, bytearray], msg: Union[bytes, bytearray] = None): """Create a new HMAC object. key: key for the keyed hash object. @@ -448,9 +306,7 @@ def __init__( """ if not isinstance(key, (bytes, bytearray)): - raise TypeError( - "key: expected bytes or bytearray, but got %r" % type(key).__name__ - ) + raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__) digestmod = sha256 @@ -527,9 +383,7 @@ def hexdigest(self) -> str: return hmac.hexdigest() -def new_hmac( - key: Union[bytes, bytearray], msg: Union[bytes, bytearray] = None -) -> "HMAC": +def new_hmac(key: Union[bytes, bytearray], msg: Union[bytes, bytearray] = None) -> "HMAC": """Create a new hashing object and return it. key: The starting key for the hash. diff --git a/adafruit_azureiot/iot_mqtt.py b/adafruit_azureiot/iot_mqtt.py index c47f785..c5a71c0 100644 --- a/adafruit_azureiot/iot_mqtt.py +++ b/adafruit_azureiot/iot_mqtt.py @@ -16,17 +16,16 @@ import json import time -import adafruit_minimqtt.adafruit_minimqtt as MQTT import adafruit_logging as logging +import adafruit_minimqtt.adafruit_minimqtt as MQTT from adafruit_logging import Logger +from . import constants from .iot_error import IoTError from .keys import compute_derived_symmetric_key from .quote import quote -from . import constants -# pylint: disable=R0903 class IoTResponse: """A response from a direct method call""" @@ -56,7 +55,6 @@ def connection_status_change(self, connected: bool) -> None: :param bool connected: True if the device is connected, otherwise false """ - # pylint: disable=W0613, R0201 def direct_method_invoked(self, method_name: str, payload: str) -> IoTResponse: """Called when a direct method is invoked @@ -67,7 +65,6 @@ def direct_method_invoked(self, method_name: str, payload: str) -> IoTResponse: """ return IoTResponse(200, "") - # pylint: disable=C0103 def cloud_to_device_message_received(self, body: str, properties: dict) -> None: """Called when a cloud to device message is received @@ -99,7 +96,6 @@ def device_twin_reported_updated( """ -# pylint: disable=R0902 class IoTMQTT: """MQTT client for Azure IoT""" @@ -110,13 +106,9 @@ def _gen_sas_token(self) -> str: self._device_sas_key, uri + "\n" + str(token_expiry) ) signature = quote(signed_hmac_sha256, "~()*!.'") - if signature.endswith( - "\n" - ): # somewhere along the crypto chain a newline is inserted + if signature.endswith("\n"): # somewhere along the crypto chain a newline is inserted signature = signature[:-1] - return "SharedAccessSignature sr={}&sig={}&se={}".format( - uri, signature, token_expiry - ) + return f"SharedAccessSignature sr={uri}&sig={signature}&se={token_expiry}" def _create_mqtt_client(self) -> None: log_text = ( @@ -152,13 +144,9 @@ def _create_mqtt_client(self) -> None: # initiate the connection using the adafruit_minimqtt library self._mqtts.connect() - # pylint: disable=C0103, W0613 def _on_connect(self, client, userdata, _, rc) -> None: self._logger.info( - "- iot_mqtt :: _on_connect :: rc = " - + str(rc) - + ", userdata = " - + str(userdata) + "- iot_mqtt :: _on_connect :: rc = " + str(rc) + ", userdata = " + str(userdata) ) self._auth_response_received = True @@ -176,11 +164,8 @@ def _on_disconnect(self, client, userdata, rc) -> None: self._callback.connection_status_change(False) def _on_publish(self, client, data, topic, msg_id) -> None: - self._logger.info( - "- iot_mqtt :: _on_publish :: " + str(data) + " on topic " + str(topic) - ) + self._logger.info("- iot_mqtt :: _on_publish :: " + str(data) + " on topic " + str(topic)) - # pylint: disable=W0703 def _handle_device_twin_update(self, client, topic: str, msg: str) -> None: self._logger.debug("- iot_mqtt :: _echo_desired :: " + topic) twin = None @@ -204,15 +189,11 @@ def _handle_device_twin_update(self, client, topic: str, msg: str) -> None: reported_version = reported["$version"] reported.pop("$version") else: - self._logger.error( - "ERROR: Unexpected payload for reported twin update => " + msg - ) + self._logger.error("ERROR: Unexpected payload for reported twin update => " + msg) return for property_name, value in reported.items(): - self._callback.device_twin_reported_updated( - property_name, value, reported_version - ) + self._callback.device_twin_reported_updated(property_name, value, reported_version) is_patch = "desired" not in twin @@ -221,15 +202,11 @@ def _handle_device_twin_update(self, client, topic: str, msg: str) -> None: desired_version = desired["$version"] desired.pop("$version") else: - self._logger.error( - "ERROR: Unexpected payload for desired twin update => " + msg - ) + self._logger.error("ERROR: Unexpected payload for desired twin update => " + msg) return for property_name, value in desired.items(): - self._callback.device_twin_desired_updated( - property_name, value, desired_version - ) + self._callback.device_twin_desired_updated(property_name, value, desired_version) def _handle_direct_method(self, client, topic: str, msg: str) -> None: index = topic.find("$rid=") @@ -258,14 +235,9 @@ def _handle_direct_method(self, client, topic: str, msg: str) -> None: ret_json = {"Value": ret_message} ret_message = json.dumps(ret_json) - next_topic = "$iothub/methods/res/{}/?$rid={}".format(ret_code, method_id) + next_topic = f"$iothub/methods/res/{ret_code}/?$rid={method_id}" self._logger.info( - "C2D: => " - + next_topic - + " with data " - + ret_message - + " and name => " - + method_name + "C2D: => " + next_topic + " with data " + ret_message + " and name => " + method_name ) self._send_common(next_topic, ret_message) @@ -302,10 +274,7 @@ def _send_common(self, topic: str, data) -> None: break except RuntimeError as runtime_error: self._logger.info( - ( - "Could not send data, retrying after 0.5 seconds: " - + str(runtime_error) - ) + "Could not send data, retrying after 0.5 seconds: " + str(runtime_error) ) retry += 1 @@ -321,7 +290,6 @@ def _get_device_settings(self) -> None: self.loop() self._send_common("$iothub/twin/GET/?$rid=0", " ") - # pylint: disable=R0913 def __init__( self, callback: IoTMQTTCallback, @@ -354,9 +322,7 @@ def __init__( self._hostname = hostname self._device_sas_key = device_sas_key self._token_expires = token_expires - self._username = "{}/{}/?api-version={}".format( - self._hostname, device_id, constants.IOTC_API_VERSION - ) + self._username = f"{self._hostname}/{device_id}/?api-version={constants.IOTC_API_VERSION}" self._passwd = self._gen_sas_token() if logger is not None: self._logger = logger @@ -366,10 +332,8 @@ def __init__( self._is_subscribed_to_twins = False def _subscribe_to_core_topics(self): - device_bound_topic = "devices/{}/messages/devicebound/#".format(self._device_id) - self._mqtts.add_topic_callback( - device_bound_topic, self._handle_cloud_to_device_message - ) + device_bound_topic = f"devices/{self._device_id}/messages/devicebound/#" + self._mqtts.add_topic_callback(device_bound_topic, self._handle_cloud_to_device_message) self._mqtts.subscribe(device_bound_topic) self._mqtts.add_topic_callback("$iothub/methods/#", self._handle_direct_method) @@ -383,9 +347,7 @@ def _subscribe_to_twin_topics(self): "$iothub/twin/PATCH/properties/desired/#" ) # twin desired property changes - self._mqtts.add_topic_callback( - "$iothub/twin/res/200/#", self._handle_device_twin_update - ) + self._mqtts.add_topic_callback("$iothub/twin/res/200/#", self._handle_device_twin_update) self._mqtts.subscribe("$iothub/twin/res/200/#") # twin properties response def connect(self) -> bool: @@ -459,9 +421,7 @@ def loop(self) -> None: self._mqtts.loop(2) gc.collect() - def send_device_to_cloud_message( - self, message, system_properties: dict = None - ) -> None: + def send_device_to_cloud_message(self, message, system_properties: dict = None) -> None: """Send a device to cloud message from this device to Azure IoT Hub :param message: The message data as a JSON string or a dictionary @@ -470,7 +430,7 @@ def send_device_to_cloud_message( :raises RuntimeError: if the internet connection is not responding or is unable to connect """ self._logger.info("- iot_mqtt :: send_device_to_cloud_message :: " + message) - topic = "devices/{}/messages/events/".format(self._device_id) + topic = f"devices/{self._device_id}/messages/events/" if system_properties is not None: firstProp = True @@ -499,7 +459,5 @@ def send_twin_patch(self, patch) -> None: :raises RuntimeError: if the internet connection is not responding or is unable to connect """ self._logger.info("- iot_mqtt :: sendProperty :: " + str(patch)) - topic = "$iothub/twin/PATCH/properties/reported/?$rid={}".format( - int(time.time()) - ) + topic = f"$iothub/twin/PATCH/properties/reported/?$rid={int(time.time())}" self._send_common(topic, patch) diff --git a/adafruit_azureiot/iotcentral_device.py b/adafruit_azureiot/iotcentral_device.py index 445a6b0..00ad25b 100644 --- a/adafruit_azureiot/iotcentral_device.py +++ b/adafruit_azureiot/iotcentral_device.py @@ -14,14 +14,16 @@ import json import time + import adafruit_logging as logging from adafruit_logging import Logger + from .device_registration import DeviceRegistration from .iot_error import IoTError from .iot_mqtt import IoTMQTT, IoTMQTTCallback, IoTResponse -class IoTCentralDevice(IoTMQTTCallback): # pylint: disable=too-many-instance-attributes +class IoTCentralDevice(IoTMQTTCallback): """A device client for the Azure IoT Central service""" def connection_status_change(self, connected: bool) -> None: @@ -30,10 +32,8 @@ def connection_status_change(self, connected: bool) -> None: :param bool connected: True if the device is connected, otherwise false """ if self.on_connection_status_changed is not None: - # pylint: disable=E1102 self.on_connection_status_changed(connected) - # pylint: disable=W0613, R0201 def direct_method_called(self, method_name: str, payload: str) -> IoTResponse: """Called when a direct method is invoked @@ -43,7 +43,6 @@ def direct_method_called(self, method_name: str, payload: str) -> IoTResponse: :rtype: IoTResponse """ if self.on_command_executed is not None: - # pylint: disable=E1102 return self.on_command_executed(method_name, payload) raise IoTError("on_command_executed not set") @@ -58,10 +57,7 @@ def device_twin_desired_updated( :param int desired_version: The version of the desired property that was updated """ if self.on_property_changed is not None: - # pylint: disable=E1102 - self.on_property_changed( - desired_property_name, desired_property_value, desired_version - ) + self.on_property_changed(desired_property_name, desired_property_value, desired_version) # when a desired property changes, update the reported to match to keep them in sync self.send_property(desired_property_name, desired_property_value) @@ -79,12 +75,10 @@ def device_twin_reported_updated( :param int reported_version: The version of the reported property that was updated """ if self.on_property_changed is not None: - # pylint: disable=E1102 self.on_property_changed( reported_property_name, reported_property_value, reported_version ) - # pylint: disable=R0913 def __init__( self, socket, diff --git a/adafruit_azureiot/iothub_device.py b/adafruit_azureiot/iothub_device.py index 02e5cdf..5a3e7de 100755 --- a/adafruit_azureiot/iothub_device.py +++ b/adafruit_azureiot/iothub_device.py @@ -18,8 +18,10 @@ pass import json + import adafruit_logging as logging from adafruit_logging import Logger + from .iot_error import IoTError from .iot_mqtt import IoTMQTT, IoTMQTTCallback, IoTResponse @@ -61,7 +63,7 @@ def _validate_keys(connection_string_parts: Mapping) -> None: ] -class IoTHubDevice(IoTMQTTCallback): # pylint: disable=too-many-instance-attributes +class IoTHubDevice(IoTMQTTCallback): """A device client for the Azure IoT Hub service""" def connection_status_change(self, connected: bool) -> None: @@ -70,10 +72,8 @@ def connection_status_change(self, connected: bool) -> None: :param bool connected: True if the device is connected, otherwise false """ if self._on_connection_status_changed is not None: - # pylint: disable=E1102 self._on_connection_status_changed(connected) - # pylint: disable=W0613, R0201 def direct_method_invoked(self, method_name: str, payload: str) -> IoTResponse: """Called when a direct method is invoked @@ -83,12 +83,10 @@ def direct_method_invoked(self, method_name: str, payload: str) -> IoTResponse: :rtype: IoTResponse """ if self._on_direct_method_invoked is not None: - # pylint: disable=E1102 return self._on_direct_method_invoked(method_name, payload) raise IoTError("on_direct_method_invoked not set") - # pylint: disable=C0103 def cloud_to_device_message_received(self, body: str, properties: dict) -> None: """Called when a cloud to device message is received @@ -96,7 +94,6 @@ def cloud_to_device_message_received(self, body: str, properties: dict) -> None: :param dict properties: The propreties sent with the mesage """ if self._on_cloud_to_device_message_received is not None: - # pylint: disable=E1102 self._on_cloud_to_device_message_received(body, properties) def device_twin_desired_updated( @@ -112,7 +109,6 @@ def device_twin_desired_updated( :param int desired_version: The version of the desired property that was updated """ if self._on_device_twin_desired_updated is not None: - # pylint: disable=E1102 self._on_device_twin_desired_updated( desired_property_name, desired_property_value, desired_version ) @@ -130,12 +126,11 @@ def device_twin_reported_updated( :param int reported_version: The version of the reported property that was updated """ if self._on_device_twin_reported_updated is not None: - # pylint: disable=E1102 self._on_device_twin_reported_updated( reported_property_name, reported_property_value, reported_version ) - def __init__( # pylint: disable=too-many-arguments + def __init__( self, socket, iface, @@ -163,9 +158,7 @@ def __init__( # pylint: disable=too-many-arguments try: cs_args = device_connection_string.split(DELIMITER) - connection_string_values = dict( - arg.split(VALUE_SEPARATOR, 1) for arg in cs_args - ) + connection_string_values = dict(arg.split(VALUE_SEPARATOR, 1) for arg in cs_args) except (ValueError, AttributeError) as e: raise ValueError( "Connection string is required and should not be empty or blank and must be" @@ -202,9 +195,7 @@ def connection_status_changed(connected: bool) -> None return self._on_connection_status_changed @on_connection_status_changed.setter - def on_connection_status_changed( - self, new_on_connection_status_changed: Callable - ) -> None: + def on_connection_status_changed(self, new_on_connection_status_changed: Callable) -> None: """A callback method that is called when the connection status is changed. This method should have the following signature: def connection_status_changed(connected: bool) -> None @@ -257,9 +248,7 @@ def on_cloud_to_device_message_received( This method should have the following signature: def cloud_to_device_message_received(body: str, properties: dict) -> None: """ - self._on_cloud_to_device_message_received = ( - new_on_cloud_to_device_message_received - ) + self._on_cloud_to_device_message_received = new_on_cloud_to_device_message_received @property def on_device_twin_desired_updated(self) -> Callable: @@ -271,9 +260,7 @@ def device_twin_desired_updated(desired_property_name: str, desired_property_val return self._on_device_twin_desired_updated @on_device_twin_desired_updated.setter - def on_device_twin_desired_updated( - self, new_on_device_twin_desired_updated: Callable - ) -> None: + def on_device_twin_desired_updated(self, new_on_device_twin_desired_updated: Callable) -> None: """A callback method that is called when the desired properties of the devices device twin are updated. This method should have the following signature: def device_twin_desired_updated(desired_property_name: str, desired_property_value, diff --git a/adafruit_azureiot/quote.py b/adafruit_azureiot/quote.py index 4053df5..d17c752 100644 --- a/adafruit_azureiot/quote.py +++ b/adafruit_azureiot/quote.py @@ -47,7 +47,6 @@ def quote(bytes_val: bytes, safe: Union[str, bytes, bytearray] = "/") -> str: return "".join([quoter(char) for char in bytes_val]) -# pylint: disable=C0103 class defaultdict: """ Default Dict Implementation. @@ -74,10 +73,8 @@ class defaultdict: """ @staticmethod - # pylint: disable=W0613 def __new__(cls, default_factory: Any = None, **kwargs: Any) -> "defaultdict": - self = super(defaultdict, cls).__new__(cls) - # pylint: disable=C0103 + self = super(defaultdict, cls).__new__(cls) # noqa: UP008 self.d = {} return self @@ -124,6 +121,6 @@ def __init__(self, safe: Union[bytes, bytearray]): def __missing__(self, b: int) -> str: # Handle a cache miss. Store quoted string in cache and return. - res = chr(b) if b in self.safe else "%{:02X}".format(b) + res = chr(b) if b in self.safe else f"%{b:02X}" self[b] = res return res diff --git a/docs/api.rst b/docs/api.rst index 46c69ff..22d0adb 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,5 +4,8 @@ .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) .. use this format as the module name: "adafruit_foo.foo" +API Reference +############# + .. automodule:: adafruit_azureiot :members: diff --git a/docs/conf.py b/docs/conf.py index 4bd1f17..5b68ee3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,12 +1,10 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) @@ -53,9 +51,7 @@ creation_year = "2019" current_year = str(datetime.datetime.now().year) year_duration = ( - current_year - if current_year == creation_year - else creation_year + " - " + current_year + current_year if current_year == creation_year else creation_year + " - " + current_year ) copyright = year_duration + " Brent Rubell, Jim Bennett, Elena Horton" author = "Brent Rubell, Jim Bennett, Elena Horton" diff --git a/examples/azureiot_esp32spi/azureiot_central_commands.py b/examples/azureiot_esp32spi/azureiot_central_commands.py index d0922e0..9de82a1 100644 --- a/examples/azureiot_esp32spi/azureiot_central_commands.py +++ b/examples/azureiot_esp32spi/azureiot_central_commands.py @@ -1,15 +1,16 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import time +from os import getenv + +import adafruit_connection_manager import board import busio -from digitalio import DigitalInOut import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_connection_manager +from digitalio import DigitalInOut # Get WiFi details and AWS Keys, ensure these are setup in settings.toml ssid = getenv("CIRCUITPY_WIFI_SSID") @@ -32,9 +33,7 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_pixel = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" # status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED @@ -44,9 +43,7 @@ # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) # status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.WiFiManager( - esp, ssid, password, status_pixel=status_pixel -) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) print("Connecting to WiFi...") @@ -99,12 +96,9 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# pylint: disable=wrong-import-position from adafruit_azureiot import IoTCentralDevice from adafruit_azureiot.iot_mqtt import IoTResponse -# pylint: enable=wrong-import-position - pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect diff --git a/examples/azureiot_esp32spi/azureiot_central_notconnected.py b/examples/azureiot_esp32spi/azureiot_central_notconnected.py index b03ab46..2ea984a 100644 --- a/examples/azureiot_esp32spi/azureiot_central_notconnected.py +++ b/examples/azureiot_esp32spi/azureiot_central_notconnected.py @@ -1,17 +1,18 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import json import random import time +from os import getenv + +import adafruit_connection_manager import board import busio -from digitalio import DigitalInOut import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_connection_manager +from digitalio import DigitalInOut # Get WiFi details and AWS Keys, ensure these are setup in settings.toml ssid = getenv("CIRCUITPY_WIFI_SSID") @@ -34,9 +35,7 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_pixel = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" # status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED @@ -46,9 +45,7 @@ # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) # status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.WiFiManager( - esp, ssid, password, status_pixel=status_pixel -) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) print("Connecting to WiFi...") @@ -93,14 +90,11 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# pylint: disable=wrong-import-position from adafruit_azureiot import ( IoTCentralDevice, IoTError, ) -# pylint: enable=wrong-import-position - pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect diff --git a/examples/azureiot_esp32spi/azureiot_central_properties.py b/examples/azureiot_esp32spi/azureiot_central_properties.py index bb8d208..41691c2 100644 --- a/examples/azureiot_esp32spi/azureiot_central_properties.py +++ b/examples/azureiot_esp32spi/azureiot_central_properties.py @@ -1,16 +1,17 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import random import time +from os import getenv + +import adafruit_connection_manager import board import busio -from digitalio import DigitalInOut import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_connection_manager +from digitalio import DigitalInOut # Get WiFi details and AWS Keys, ensure these are setup in settings.toml ssid = getenv("CIRCUITPY_WIFI_SSID") @@ -33,9 +34,7 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_pixel = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" # status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED @@ -45,9 +44,7 @@ # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) # status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.WiFiManager( - esp, ssid, password, status_pixel=status_pixel -) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) print("Connecting to WiFi...") @@ -100,7 +97,7 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -from adafruit_azureiot import IoTCentralDevice # pylint: disable=wrong-import-position +from adafruit_azureiot import IoTCentralDevice pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) diff --git a/examples/azureiot_esp32spi/azureiot_central_simpletest.py b/examples/azureiot_esp32spi/azureiot_central_simpletest.py index 01faade..d3a5eca 100644 --- a/examples/azureiot_esp32spi/azureiot_central_simpletest.py +++ b/examples/azureiot_esp32spi/azureiot_central_simpletest.py @@ -1,17 +1,18 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import json import random import time +from os import getenv + +import adafruit_connection_manager import board import busio -from digitalio import DigitalInOut import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_connection_manager +from digitalio import DigitalInOut # Get WiFi details and AWS Keys, ensure these are setup in settings.toml ssid = getenv("CIRCUITPY_WIFI_SSID") @@ -34,9 +35,7 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_pixel = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" # status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED @@ -46,9 +45,7 @@ # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) # status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.WiFiManager( - esp, ssid, password, status_pixel=status_pixel -) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) print("Connecting to WiFi...") @@ -101,7 +98,7 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -from adafruit_azureiot import IoTCentralDevice # pylint: disable=wrong-import-position +from adafruit_azureiot import IoTCentralDevice pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) diff --git a/examples/azureiot_esp32spi/azureiot_hub_directmethods.py b/examples/azureiot_esp32spi/azureiot_hub_directmethods.py index 17466e9..91300a6 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_directmethods.py +++ b/examples/azureiot_esp32spi/azureiot_hub_directmethods.py @@ -1,15 +1,16 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import time +from os import getenv + +import adafruit_connection_manager import board import busio -from digitalio import DigitalInOut import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_connection_manager +from digitalio import DigitalInOut # Get WiFi details and Azure keys, ensure these are setup in settings.toml ssid = getenv("CIRCUITPY_WIFI_SSID") @@ -30,9 +31,7 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_pixel = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" # status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED @@ -42,9 +41,7 @@ # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) # status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.WiFiManager( - esp, ssid, password, status_pixel=status_pixel -) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) print("Connecting to WiFi...") @@ -91,12 +88,9 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -# pylint: disable=wrong-import-position from adafruit_azureiot import IoTHubDevice from adafruit_azureiot.iot_mqtt import IoTResponse -# pylint: enable=wrong-import-position - pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) # Create an IoT Hub device client and connect diff --git a/examples/azureiot_esp32spi/azureiot_hub_messages.py b/examples/azureiot_esp32spi/azureiot_hub_messages.py index f242be5..6ce01c1 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_messages.py +++ b/examples/azureiot_esp32spi/azureiot_hub_messages.py @@ -1,17 +1,18 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import json import random import time +from os import getenv + +import adafruit_connection_manager import board import busio -from digitalio import DigitalInOut import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_connection_manager +from digitalio import DigitalInOut # Get WiFi details and Azure keys, ensure these are setup in settings.toml ssid = getenv("CIRCUITPY_WIFI_SSID") @@ -32,9 +33,7 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_pixel = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" # status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED @@ -44,9 +43,7 @@ # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) # status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.WiFiManager( - esp, ssid, password, status_pixel=status_pixel -) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) print("Connecting to WiFi...") @@ -93,7 +90,7 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position +from adafruit_azureiot import IoTHubDevice pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) diff --git a/examples/azureiot_esp32spi/azureiot_hub_simpletest.py b/examples/azureiot_esp32spi/azureiot_hub_simpletest.py index f92247b..bc36fc3 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_simpletest.py +++ b/examples/azureiot_esp32spi/azureiot_hub_simpletest.py @@ -1,17 +1,18 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import json import random import time +from os import getenv + +import adafruit_connection_manager import board import busio -from digitalio import DigitalInOut import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_connection_manager +from digitalio import DigitalInOut # Get WiFi details and Azure keys, ensure these are setup in settings.toml ssid = getenv("CIRCUITPY_WIFI_SSID") @@ -32,9 +33,7 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_pixel = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" # status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED @@ -44,9 +43,7 @@ # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) # status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.WiFiManager( - esp, ssid, password, status_pixel=status_pixel -) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) print("Connecting to WiFi...") @@ -93,7 +90,7 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position +from adafruit_azureiot import IoTHubDevice pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) diff --git a/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py b/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py index 1f7cdac..1c722a5 100644 --- a/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py +++ b/examples/azureiot_esp32spi/azureiot_hub_twin_operations.py @@ -1,16 +1,17 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import random import time +from os import getenv + +import adafruit_connection_manager import board import busio -from digitalio import DigitalInOut import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_connection_manager +from digitalio import DigitalInOut # Get WiFi details and Azure keys, ensure these are setup in settings.toml ssid = getenv("CIRCUITPY_WIFI_SSID") @@ -31,9 +32,7 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_pixel = neopixel.NeoPixel( - board.NEOPIXEL, 1, brightness=0.2 -) # Uncomment for Most Boards +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" # status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) # Uncomment below for an externally defined RGB LED @@ -43,9 +42,7 @@ # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) # status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.WiFiManager( - esp, ssid, password, status_pixel=status_pixel -) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) print("Connecting to WiFi...") @@ -95,7 +92,7 @@ # # From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle: # * adafruit-circuitpython-minimqtt -from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position +from adafruit_azureiot import IoTHubDevice pool = adafruit_connection_manager.get_radio_socketpool(esp) ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp) diff --git a/examples/azureiot_native_networking/azureiot_central_commands.py b/examples/azureiot_native_networking/azureiot_central_commands.py index 3dea2ed..d123648 100644 --- a/examples/azureiot_native_networking/azureiot_central_commands.py +++ b/examples/azureiot_native_networking/azureiot_central_commands.py @@ -1,14 +1,14 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import time +from os import getenv +import adafruit_connection_manager +import adafruit_ntp import rtc import wifi -import adafruit_connection_manager -import adafruit_ntp from adafruit_azureiot import IoTCentralDevice from adafruit_azureiot.iot_mqtt import IoTResponse diff --git a/examples/azureiot_native_networking/azureiot_central_notconnected.py b/examples/azureiot_native_networking/azureiot_central_notconnected.py index 55a3c48..ebeba29 100644 --- a/examples/azureiot_native_networking/azureiot_central_notconnected.py +++ b/examples/azureiot_native_networking/azureiot_central_notconnected.py @@ -1,16 +1,16 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import json import random import time +from os import getenv +import adafruit_connection_manager +import adafruit_ntp import rtc import wifi -import adafruit_connection_manager -import adafruit_ntp from adafruit_azureiot import ( IoTCentralDevice, IoTError, diff --git a/examples/azureiot_native_networking/azureiot_central_properties.py b/examples/azureiot_native_networking/azureiot_central_properties.py index 3c49cec..cff1972 100644 --- a/examples/azureiot_native_networking/azureiot_central_properties.py +++ b/examples/azureiot_native_networking/azureiot_central_properties.py @@ -1,15 +1,15 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import random import time +from os import getenv +import adafruit_connection_manager +import adafruit_ntp import rtc import wifi -import adafruit_connection_manager -import adafruit_ntp from adafruit_azureiot import IoTCentralDevice # Get WiFi details and AWS Keys, ensure these are setup in settings.toml diff --git a/examples/azureiot_native_networking/azureiot_central_simpletest.py b/examples/azureiot_native_networking/azureiot_central_simpletest.py index 018de9f..6a284b2 100644 --- a/examples/azureiot_native_networking/azureiot_central_simpletest.py +++ b/examples/azureiot_native_networking/azureiot_central_simpletest.py @@ -1,16 +1,16 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import json import random import time +from os import getenv +import adafruit_connection_manager +import adafruit_ntp import rtc import wifi -import adafruit_connection_manager -import adafruit_ntp from adafruit_azureiot import IoTCentralDevice # Get WiFi details and AWS Keys, ensure these are setup in settings.toml diff --git a/examples/azureiot_native_networking/azureiot_hub_directmethods.py b/examples/azureiot_native_networking/azureiot_hub_directmethods.py index a61bb54..5bd6386 100644 --- a/examples/azureiot_native_networking/azureiot_hub_directmethods.py +++ b/examples/azureiot_native_networking/azureiot_hub_directmethods.py @@ -1,14 +1,14 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import time +from os import getenv +import adafruit_connection_manager +import adafruit_ntp import rtc import wifi -import adafruit_connection_manager -import adafruit_ntp from adafruit_azureiot import IoTHubDevice from adafruit_azureiot.iot_mqtt import IoTResponse diff --git a/examples/azureiot_native_networking/azureiot_hub_messages.py b/examples/azureiot_native_networking/azureiot_hub_messages.py index 32dc3e1..2f64c52 100644 --- a/examples/azureiot_native_networking/azureiot_hub_messages.py +++ b/examples/azureiot_native_networking/azureiot_hub_messages.py @@ -1,16 +1,16 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import json import random import time +from os import getenv +import adafruit_connection_manager +import adafruit_ntp import rtc import wifi -import adafruit_connection_manager -import adafruit_ntp from adafruit_azureiot import IoTHubDevice # Get WiFi details and Azure keys, ensure these are setup in settings.toml diff --git a/examples/azureiot_native_networking/azureiot_hub_simpletest.py b/examples/azureiot_native_networking/azureiot_hub_simpletest.py index 1ebf496..1804071 100644 --- a/examples/azureiot_native_networking/azureiot_hub_simpletest.py +++ b/examples/azureiot_native_networking/azureiot_hub_simpletest.py @@ -1,16 +1,16 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import json import random import time +from os import getenv +import adafruit_connection_manager +import adafruit_ntp import rtc import wifi -import adafruit_connection_manager -import adafruit_ntp from adafruit_azureiot import IoTHubDevice # Get WiFi details and Azure keys, ensure these are setup in settings.toml diff --git a/examples/azureiot_native_networking/azureiot_hub_twin_operations.py b/examples/azureiot_native_networking/azureiot_hub_twin_operations.py index 2bea634..2809ee4 100644 --- a/examples/azureiot_native_networking/azureiot_hub_twin_operations.py +++ b/examples/azureiot_native_networking/azureiot_hub_twin_operations.py @@ -1,15 +1,15 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from os import getenv import random import time +from os import getenv +import adafruit_connection_manager +import adafruit_ntp import rtc import wifi -import adafruit_connection_manager -import adafruit_ntp from adafruit_azureiot import IoTHubDevice # Get WiFi details and Azure keys, ensure these are setup in settings.toml diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..1b887b1 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,107 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +target-version = "py38" +line-length = 100 + +[lint] +preview = true +select = ["I", "PL", "UP"] + +extend-select = [ + "D419", # empty-docstring + "E501", # line-too-long + "W291", # trailing-whitespace + "PLC0414", # useless-import-alias + "PLC2401", # non-ascii-name + "PLC2801", # unnecessary-dunder-call + "PLC3002", # unnecessary-direct-lambda-call + "E999", # syntax-error + "PLE0101", # return-in-init + "F706", # return-outside-function + "F704", # yield-outside-function + "PLE0116", # continue-in-finally + "PLE0117", # nonlocal-without-binding + "PLE0241", # duplicate-bases + "PLE0302", # unexpected-special-method-signature + "PLE0604", # invalid-all-object + "PLE0605", # invalid-all-format + "PLE0643", # potential-index-error + "PLE0704", # misplaced-bare-raise + "PLE1141", # dict-iter-missing-items + "PLE1142", # await-outside-async + "PLE1205", # logging-too-many-args + "PLE1206", # logging-too-few-args + "PLE1307", # bad-string-format-type + "PLE1310", # bad-str-strip-call + "PLE1507", # invalid-envvar-value + "PLE2502", # bidirectional-unicode + "PLE2510", # invalid-character-backspace + "PLE2512", # invalid-character-sub + "PLE2513", # invalid-character-esc + "PLE2514", # invalid-character-nul + "PLE2515", # invalid-character-zero-width-space + "PLR0124", # comparison-with-itself + "PLR0202", # no-classmethod-decorator + "PLR0203", # no-staticmethod-decorator + "UP004", # useless-object-inheritance + "PLR0206", # property-with-parameters + "PLR0904", # too-many-public-methods + "PLR0911", # too-many-return-statements + "PLR0912", # too-many-branches + "PLR0913", # too-many-arguments + "PLR0914", # too-many-locals + "PLR0915", # too-many-statements + "PLR0916", # too-many-boolean-expressions + "PLR1702", # too-many-nested-blocks + "PLR1704", # redefined-argument-from-local + "PLR1711", # useless-return + "C416", # unnecessary-comprehension + "PLR1733", # unnecessary-dict-index-lookup + "PLR1736", # unnecessary-list-index-lookup + + # ruff reports this rule is unstable + #"PLR6301", # no-self-use + + "PLW0108", # unnecessary-lambda + "PLW0120", # useless-else-on-loop + "PLW0127", # self-assigning-variable + "PLW0129", # assert-on-string-literal + "B033", # duplicate-value + "PLW0131", # named-expr-without-context + "PLW0245", # super-without-brackets + "PLW0406", # import-self + "PLW0602", # global-variable-not-assigned + "PLW0603", # global-statement + "PLW0604", # global-at-module-level + + # fails on the try: import typing used by libraries + #"F401", # unused-import + + "F841", # unused-variable + "E722", # bare-except + "PLW0711", # binary-op-exception + "PLW1501", # bad-open-mode + "PLW1508", # invalid-envvar-default + "PLW1509", # subprocess-popen-preexec-fn + "PLW2101", # useless-with-lock + "PLW3301", # nested-min-max +] + +ignore = [ + "PLR2004", # magic-value-comparison + "UP030", # format literals + "PLW1514", # unspecified-encoding + "PLR0913", # too-many-arguments + "PLR0915", # too-many-statements + "PLR0917", # too-many-positional-arguments + "PLR0904", # too-many-public-methods + "PLR0912", # too-many-branches + "PLR0916", # too-many-boolean-expressions + "PLR6301", # could-be-static no-self-use + "PLC0415", # import outside toplevel +] + +[format] +line-ending = "lf" From 37bbba03f6b72c98cbba8a5da5fb4949cb1da88f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Jun 2025 10:00:20 -0500 Subject: [PATCH 7/7] update rtd.yml file Signed-off-by: foamyguy --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 88bca9f..255dafd 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -12,7 +12,7 @@ sphinx: configuration: docs/conf.py build: - os: ubuntu-20.04 + os: ubuntu-lts-latest tools: python: "3" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy