Skip to content

Commit

Permalink
Merge pull request #17 from tcfranks/main
Browse files Browse the repository at this point in the history
Add Missing Type Annotations
  • Loading branch information
tekktrik authored Sep 3, 2022
2 parents 7c3c3f9 + b80bd5b commit ca46b27
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions adafruit_us100.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@

import time

try:
from typing import Optional
from busio import UART
except ImportError:
pass


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

def __init__(self, uart):
def __init__(self, uart: UART) -> None:
self._uart = uart

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

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

0 comments on commit ca46b27

Please sign in to comment.