Skip to content

Commit 0d96401

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

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

adafruit_tfmini.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
import time
2626
import struct
2727

28+
try:
29+
import typing # pylint: disable=unused-import
30+
from busio import UART
31+
except ImportError:
32+
pass
33+
2834
__version__ = "0.0.0+auto.0"
2935
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_TFmini.git"
3036

@@ -46,7 +52,7 @@ class TFmini:
4652
:param timeout: how long we'll wait for valid data or response, in seconds. Default is 1
4753
"""
4854

49-
def __init__(self, uart, *, timeout=1):
55+
def __init__(self, uart: UART, *, timeout: int = 1) -> None:
5056
self._uart = uart
5157
self._uart.baudrate = 115200
5258
self._uart.reset_input_buffer()
@@ -55,7 +61,7 @@ def __init__(self, uart, *, timeout=1):
5561
self._mode = None
5662

5763
@property
58-
def distance(self):
64+
def distance(self) -> None:
5965
"""The most recent distance measurement in centimeters"""
6066
try:
6167
self._uart.reset_input_buffer()
@@ -87,24 +93,24 @@ def distance(self):
8793
raise RuntimeError("Timed out looking for valid data")
8894

8995
@property
90-
def strength(self):
96+
def strength(self) -> int:
9197
"""The signal validity, higher value means better measurement"""
9298
_ = self.distance # trigger distance measurement
9399
return self._strength
94100

95101
@property
96-
def mode(self):
102+
def mode(self) -> int:
97103
"""The measurement mode can be MODE_SHORT (2) or MODE_LONG (7)"""
98104
_ = self.distance # trigger distance measurement
99105
return self._mode
100106

101107
@mode.setter
102-
def mode(self, newmode):
108+
def mode(self, newmode: int) -> None:
103109
if not newmode in (MODE_LONG, MODE_SHORT):
104110
raise ValueError("Invalid mode")
105111
self._set_config(_CONFIGPARAM + bytes([0, 0, newmode, 0x11]))
106112

107-
def _set_config(self, command):
113+
def _set_config(self, command: int) -> None:
108114
"""Manager for sending commands, put sensor into config mode, config,
109115
then exit configuration mode!"""
110116
self._uart.write(_STARTCONFIG)

0 commit comments

Comments
 (0)