From 77fc12eace8086cef42adf3b57fec646d47ccee3 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Fri, 2 Sep 2022 13:32:48 -0400 Subject: [PATCH 1/3] Add Missing Type Annotations --- adafruit_us100.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/adafruit_us100.py b/adafruit_us100.py index 0ee2f1a..bdb982c 100644 --- a/adafruit_us100.py +++ b/adafruit_us100.py @@ -25,15 +25,21 @@ import time +try: + from typing import Union + 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): self._uart = uart @property - def distance(self): + def distance(self) -> 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 @@ -67,7 +73,7 @@ def distance(self): return dist @property - def temperature(self): + def temperature(self) -> Union[None, int]: """Return the on-chip temperature, in Celsius""" for _ in range(2): # Attempt to read twice. self._uart.write(bytes([0x50])) From 6e56a6f684ba2e76cb295016b6f08147c6a1fc9e Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Fri, 2 Sep 2022 15:52:34 -0400 Subject: [PATCH 2/3] Add Missing Type Annotations --- adafruit_us100.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_us100.py b/adafruit_us100.py index bdb982c..d9d6e4f 100644 --- a/adafruit_us100.py +++ b/adafruit_us100.py @@ -26,7 +26,7 @@ import time try: - from typing import Union + from typing import Optional from busio import UART except ImportError: pass @@ -35,11 +35,11 @@ class US100: """Control a US-100 ultrasonic range sensor.""" - def __init__(self, uart: UART): + def __init__(self, uart: UART) -> None: self._uart = uart @property - def distance(self) -> float: + 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 @@ -73,7 +73,7 @@ def distance(self) -> float: return dist @property - def temperature(self) -> Union[None, int]: + 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])) From b80bd5b128afde05237026541216247d4f0b2486 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Fri, 2 Sep 2022 16:49:05 -0400 Subject: [PATCH 3/3] Add Missing Type Annotations --- adafruit_us100.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_us100.py b/adafruit_us100.py index d9d6e4f..9a8adee 100644 --- a/adafruit_us100.py +++ b/adafruit_us100.py @@ -51,7 +51,7 @@ def distance(self) -> Optional[float]: 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]))