Skip to content

Commit 8bfc83c

Browse files
authored
Merge pull request #6 from tekktrik/feature/add-typing
Added typing
2 parents 38c1fa1 + 39608ce commit 8bfc83c

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

adafruit_airlift/esp32.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
import busio
1717
from digitalio import DigitalInOut
1818

19+
try:
20+
from typing import Optional
21+
from microcontroller import Pin
22+
from busio import SPI
23+
from _bleio import Adapter
24+
except ImportError:
25+
pass
26+
1927

2028
class ESP32:
2129
"""Class to manage ESP32 running NINA firmware for WiFi or Bluetooth."""
@@ -34,14 +42,14 @@ class ESP32:
3442
def __init__(
3543
self,
3644
*,
37-
reset=None,
38-
reset_high=False,
39-
gpio0=None,
40-
busy=None,
41-
chip_select=None,
42-
tx=None,
43-
rx=None,
44-
spi=None
45+
reset: Optional[Pin] = None,
46+
reset_high: bool = False,
47+
gpio0: Optional[Pin] = None,
48+
busy: Optional[Pin] = None,
49+
chip_select: Optional[Pin] = None,
50+
tx: Optional[Pin] = None,
51+
rx: Optional[Pin] = None,
52+
spi: Optional[SPI] = None
4553
):
4654

4755
"""Create an ESP32 instance, passing the objects needed to reset and communicate
@@ -89,7 +97,7 @@ def __init__(
8997
# Used for WiFi mode.
9098
self._spi = spi
9199

92-
def reset(self, mode, debug=False):
100+
def reset(self, mode: int, debug: bool = False) -> None:
93101
"""Do hard reset of the ESP32.
94102
95103
:param mode: One of `ESP32.NOT_IN_USE`, `ESP32.BOOTLOADER`, `ESP32.BLUETOOTH`, `ESP32.WIFI`.
@@ -145,7 +153,7 @@ def reset(self, mode, debug=False):
145153
self._mode = mode
146154

147155
# pylint: disable=invalid-name
148-
def start_bluetooth(self, debug=False):
156+
def start_bluetooth(self, debug: bool = False) -> Adapter:
149157
"""Set up the ESP32 in HCI Bluetooth mode, if it is not already doing something else.
150158
151159
:param debug bool: Print out some debugging information.
@@ -196,7 +204,7 @@ def stop_bluetooth(self):
196204
self._uart.deinit()
197205
self._uart = None
198206

199-
def start_wifi(self, debug=False):
207+
def start_wifi(self, debug: bool = False) -> SPI:
200208
"""Start WiFi on the ESP32.
201209
202210
:return: the ``busio.SPI`` object that will be used to communicate with the ESP32.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Uncomment the below if you use native CircuitPython modules such as
2525
# digitalio, micropython and busio. List the modules you use. Without it, the
2626
# autodoc module docs will fail to generate with a warning.
27-
autodoc_mock_imports = ["board", "digitalio", "busio"]
27+
autodoc_mock_imports = ["board", "digitalio", "busio", "_bleio"]
2828

2929

3030
intersphinx_mapping = {

0 commit comments

Comments
 (0)