Skip to content

Commit ca46b27

Browse files
authored
Merge pull request #17 from tcfranks/main
Add Missing Type Annotations
2 parents 7c3c3f9 + b80bd5b commit ca46b27

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

adafruit_us100.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@
2525

2626
import time
2727

28+
try:
29+
from typing import Optional
30+
from busio import UART
31+
except ImportError:
32+
pass
33+
2834

2935
class US100:
3036
"""Control a US-100 ultrasonic range sensor."""
3137

32-
def __init__(self, uart):
38+
def __init__(self, uart: UART) -> None:
3339
self._uart = uart
3440

3541
@property
36-
def distance(self):
42+
def distance(self) -> Optional[float]:
3743
"""Return the distance measured by the sensor in cm.
3844
This is the function that will be called most often in user code.
3945
If no signal is received, return ``None``. This can happen when the
@@ -45,7 +51,7 @@ def distance(self):
4551
for the sensor to handle. In my experience, the sensor can not detect
4652
objects over 460 cm away.
4753
:return: Distance in centimeters.
48-
:rtype: float
54+
:rtype: float or None
4955
"""
5056
for _ in range(2): # Attempt to read twice.
5157
self._uart.write(bytes([0x55]))
@@ -67,7 +73,7 @@ def distance(self):
6773
return dist
6874

6975
@property
70-
def temperature(self):
76+
def temperature(self) -> Optional[int]:
7177
"""Return the on-chip temperature, in Celsius"""
7278
for _ in range(2): # Attempt to read twice.
7379
self._uart.write(bytes([0x50]))

0 commit comments

Comments
 (0)