Skip to content

Commit cfbf876

Browse files
committed
Add Missing Type Annotations
1 parent 0d96401 commit cfbf876

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

adafruit_tfmini.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
try:
2929
import typing # pylint: disable=unused-import
30+
from typing_extensions import Literal
31+
from circuitpython_typing import ReadableBuffer
3032
from busio import UART
3133
except ImportError:
3234
pass
@@ -52,7 +54,7 @@ class TFmini:
5254
:param timeout: how long we'll wait for valid data or response, in seconds. Default is 1
5355
"""
5456

55-
def __init__(self, uart: UART, *, timeout: int = 1) -> None:
57+
def __init__(self, uart: UART, *, timeout: float = 1) -> None:
5658
self._uart = uart
5759
self._uart.baudrate = 115200
5860
self._uart.reset_input_buffer()
@@ -61,7 +63,7 @@ def __init__(self, uart: UART, *, timeout: int = 1) -> None:
6163
self._mode = None
6264

6365
@property
64-
def distance(self) -> None:
66+
def distance(self) -> int:
6567
"""The most recent distance measurement in centimeters"""
6668
try:
6769
self._uart.reset_input_buffer()
@@ -99,18 +101,18 @@ def strength(self) -> int:
99101
return self._strength
100102

101103
@property
102-
def mode(self) -> int:
104+
def mode(self) -> Literal[2, 7]:
103105
"""The measurement mode can be MODE_SHORT (2) or MODE_LONG (7)"""
104106
_ = self.distance # trigger distance measurement
105107
return self._mode
106108

107109
@mode.setter
108-
def mode(self, newmode: int) -> None:
110+
def mode(self, newmode: Literal[MODE_LONG, MODE_SHORT]) -> None:
109111
if not newmode in (MODE_LONG, MODE_SHORT):
110112
raise ValueError("Invalid mode")
111113
self._set_config(_CONFIGPARAM + bytes([0, 0, newmode, 0x11]))
112114

113-
def _set_config(self, command: int) -> None:
115+
def _set_config(self, command: ReadableBuffer) -> None:
114116
"""Manager for sending commands, put sensor into config mode, config,
115117
then exit configuration mode!"""
116118
self._uart.write(_STARTCONFIG)

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44

55
Adafruit-Blinka
66
pyserial
7+
adafruit-circuitpython-typing
8+
typing-extensions~=4.0

0 commit comments

Comments
 (0)