From d9d75362dc7c38160ce349e56db18f985e7c9959 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Fri, 5 Nov 2021 18:58:47 -0400 Subject: [PATCH 1/4] Added typing --- adafruit_airlift/esp32.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/adafruit_airlift/esp32.py b/adafruit_airlift/esp32.py index 508966a..f2786a1 100644 --- a/adafruit_airlift/esp32.py +++ b/adafruit_airlift/esp32.py @@ -16,6 +16,14 @@ import busio from digitalio import DigitalInOut +try: + from typing import Optional + from microcontroller import Pin + from busio import SPI + from _bleio import Adapter +except ImportError: + pass + class ESP32: """Class to manage ESP32 running NINA firmware for WiFi or Bluetooth.""" @@ -34,14 +42,14 @@ class ESP32: def __init__( self, *, - reset=None, - reset_high=False, - gpio0=None, - busy=None, - chip_select=None, - tx=None, - rx=None, - spi=None + reset: Optional[Pin] = None, + reset_high: bool = False, + gpio0: Optional[Pin] = None, + busy: Optional[Pin] = None, + chip_select: Optional[Pin] = None, + tx: Optional[Pin] = None, + rx: Optional[Pin] = None, + spi: Optional[SPI] = None ): """Create an ESP32 instance, passing the objects needed to reset and communicate @@ -89,7 +97,7 @@ def __init__( # Used for WiFi mode. self._spi = spi - def reset(self, mode, debug=False): + def reset(self, mode: int, debug: bool = False): """Do hard reset of the ESP32. :param mode: One of `ESP32.NOT_IN_USE`, `ESP32.BOOTLOADER`, `ESP32.BLUETOOTH`, `ESP32.WIFI`. @@ -145,7 +153,7 @@ def reset(self, mode, debug=False): self._mode = mode # pylint: disable=invalid-name - def start_bluetooth(self, debug=False): + def start_bluetooth(self, debug: bool = False) -> Adapter: """Set up the ESP32 in HCI Bluetooth mode, if it is not already doing something else. :param debug bool: Print out some debugging information. @@ -196,7 +204,7 @@ def stop_bluetooth(self): self._uart.deinit() self._uart = None - def start_wifi(self, debug=False): + def start_wifi(self, debug: bool = False) -> SPI: """Start WiFi on the ESP32. :return: the ``busio.SPI`` object that will be used to communicate with the ESP32. From cb79f48a6215a1b52f3c19fb8d0b70e93dc0dfb0 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Fri, 12 Nov 2021 09:18:46 -0500 Subject: [PATCH 2/4] Added _bleio to mock_imports --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index f0fee86..b2f753a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,7 +24,7 @@ # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -autodoc_mock_imports = ["board", "digitalio", "busio"] +autodoc_mock_imports = ["board", "digitalio", "busio", "_bleio"] intersphinx_mapping = { From c8731fc5d81b69d6081437dc15d560e7cbe9252e Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Fri, 12 Nov 2021 09:44:54 -0500 Subject: [PATCH 3/4] Add typehint for return type None Co-authored-by: Dan Halbert --- adafruit_airlift/esp32.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_airlift/esp32.py b/adafruit_airlift/esp32.py index f2786a1..50ccea4 100644 --- a/adafruit_airlift/esp32.py +++ b/adafruit_airlift/esp32.py @@ -97,7 +97,7 @@ def __init__( # Used for WiFi mode. self._spi = spi - def reset(self, mode: int, debug: bool = False): + def reset(self, mode: int, debug: bool = False) -> None: """Do hard reset of the ESP32. :param mode: One of `ESP32.NOT_IN_USE`, `ESP32.BOOTLOADER`, `ESP32.BLUETOOTH`, `ESP32.WIFI`. From 42ae00ea3c00f79eb9c0d643642efdd39e4d3441 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Fri, 12 Nov 2021 11:19:04 -0500 Subject: [PATCH 4/4] Add adafruit-blinka-bleio to docs/requirements.txt --- adafruit_airlift/esp32.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_airlift/esp32.py b/adafruit_airlift/esp32.py index f2786a1..50ccea4 100644 --- a/adafruit_airlift/esp32.py +++ b/adafruit_airlift/esp32.py @@ -97,7 +97,7 @@ def __init__( # Used for WiFi mode. self._spi = spi - def reset(self, mode: int, debug: bool = False): + def reset(self, mode: int, debug: bool = False) -> None: """Do hard reset of the ESP32. :param mode: One of `ESP32.NOT_IN_USE`, `ESP32.BOOTLOADER`, `ESP32.BLUETOOTH`, `ESP32.WIFI`.