Skip to content

Add Missing Type Annotations #27

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 23, 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
21 changes: 13 additions & 8 deletions adafruit_max31855.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@

from adafruit_bus_device.spi_device import SPIDevice

try:
import typing # pylint: disable=unused-import
from digitalio import DigitalInOut
from busio import SPI
except ImportError:
pass

__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MAX31855.git"

Expand Down Expand Up @@ -71,11 +78,11 @@ class MAX31855:
temperature = sensor.temperature
"""

def __init__(self, spi, cs):
def __init__(self, spi: SPI, cs: DigitalInOut) -> None:
self.spi_device = SPIDevice(spi, cs)
self.data = bytearray(4)

def _read(self, internal=False):
def _read(self, internal: bool = False) -> int:
with self.spi_device as spi:
spi.readinto(self.data) # pylint: disable=no-member
if self.data[3] & 0x01:
Expand All @@ -94,17 +101,17 @@ def _read(self, internal=False):
return temp

@property
def temperature(self):
def temperature(self) -> float:
"""Thermocouple temperature in degrees Celsius."""
return self._read() / 4

@property
def reference_temperature(self):
def reference_temperature(self) -> float:
"""Internal reference temperature in degrees Celsius."""
return self._read(True) * 0.0625

@property
def temperature_NIST(self):
def temperature_NIST(self) -> float:
"""
Thermocouple temperature in degrees Celsius, computed using
raw voltages and NIST approximation for Type K, see:
Expand Down Expand Up @@ -186,9 +193,7 @@ def temperature_NIST(self):
-3.110810e-08,
)
else:
raise RuntimeError(
"Total thermoelectric voltage out of range:{}".format(VTOTAL)
)
raise RuntimeError(f"Total thermoelectric voltage out of range:{VTOTAL}")
# compute temperature
TEMPERATURE = 0
for n, c in enumerate(DCOEF):
Expand Down