Skip to content

Added typing #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions adafruit_airlift/esp32.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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
Expand Down Expand Up @@ -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) -> None:
"""Do hard reset of the ESP32.

:param mode: One of `ESP32.NOT_IN_USE`, `ESP32.BOOTLOADER`, `ESP32.BLUETOOTH`, `ESP32.WIFI`.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down