8000 Add Missing Type Annotations by tcfranks · Pull Request #17 · adafruit/Adafruit_CircuitPython_US100 · GitHub
[go: up one dir, main page]

Skip to content

Add Missing Type Annotations #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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