Add Missing Type Annotations

This commit is contained in:
Thomas Franks 2023-02-09 15:12:59 -05:00
parent f19d2424c5
commit 91f3385ba7
5 changed files with 112 additions and 46 deletions

View file

@ -17,6 +17,12 @@ using UART.
__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PN532.git"
try:
from typing import Optional
from digitalio import DigitalInOut
from busio import UART
except ImportError:
pass
import time
from adafruit_pn532.adafruit_pn532 import PN532, BusyError
@ -25,7 +31,9 @@ from adafruit_pn532.adafruit_pn532 import PN532, BusyError
class PN532_UART(PN532):
"""Driver for the PN532 connected over Serial UART"""
def __init__(self, uart, *, reset=None, debug=False):
def __init__(
self, uart: UART, *, reset: Optional[DigitalInOut] = None, debug: bool = False
) -> None:
"""Create an instance of the PN532 class using Serial connection.
Optional reset pin and debugging output.
"""
@ -33,7 +41,7 @@ class PN532_UART(PN532):
self._uart = uart
super().__init__(debug=debug, reset=reset)
def _wakeup(self):
def _wakeup(self) -> None:
"""Send any special commands/data to wake up PN532"""
if self._reset_pin:
self._reset_pin.value = True
@ -44,7 +52,7 @@ class PN532_UART(PN532):
) # wake up!
self.SAM_configuration()
def _wait_ready(self, timeout=1):
def _wait_ready(self, timeout: float = 1) -> bool:
"""Wait `timeout` seconds"""
timestamp = time.monotonic()
while (time.monotonic() - timestamp) < timeout:
@ -54,7 +62,7 @@ class PN532_UART(PN532):
# Timed out!
return False
def _read_data(self, count):
def _read_data(self, count: int) -> bytearray:
"""Read a specified count of bytes from the PN532."""
frame = self._uart.read(count)
if not frame:
@ -63,7 +71,7 @@ class PN532_UART(PN532):
print("Reading: ", [hex(i) for i in frame])
return frame
def _write_data(self, framebytes):
def _write_data(self, framebytes: bytearray) -> None:
"""Write a specified count of bytes to the PN532"""
self._uart.reset_input_buffer()
self._uart.write(framebytes)