Skip to content

Commit c33c7cd

Browse files
authored
Merge pull request #27 from tcfranks/main
Add Missing Type Annotations
2 parents 84c8d4e + 8d86a7e commit c33c7cd

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

adafruit_max31855.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232

3333
from adafruit_bus_device.spi_device import SPIDevice
3434

35+
try:
36+
import typing # pylint: disable=unused-import
37+
from digitalio import DigitalInOut
38+
from busio import SPI
39+
except ImportError:
40+
pass
41+
3542
__version__ = "0.0.0+auto.0"
3643
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MAX31855.git"
3744

@@ -71,11 +78,11 @@ class MAX31855:
7178
temperature = sensor.temperature
7279
"""
7380

74-
def __init__(self, spi, cs):
81+
def __init__(self, spi: SPI, cs: DigitalInOut) -> None:
7582
self.spi_device = SPIDevice(spi, cs)
7683
self.data = bytearray(4)
7784

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

96103
@property
97-
def temperature(self):
104+
def temperature(self) -> float:
98105
"""Thermocouple temperature in degrees Celsius."""
99106
return self._read() / 4
100107

101108
@property
102-
def reference_temperature(self):
109+
def reference_temperature(self) -> float:
103110
"""Internal reference temperature in degrees Celsius."""
104111
return self._read(True) * 0.0625
105112

106113
@property
107-
def temperature_NIST(self):
114+
def temperature_NIST(self) -> float:
108115
"""
109116
Thermocouple temperature in degrees Celsius, computed using
110117
raw voltages and NIST approximation for Type K, see:
@@ -186,9 +193,7 @@ def temperature_NIST(self):
186193
-3.110810e-08,
187194
)
188195
else:
189-
raise RuntimeError(
190-
"Total thermoelectric voltage out of range:{}".format(VTOTAL)
191-
)
196+
raise RuntimeError(f"Total thermoelectric voltage out of range:{VTOTAL}")
192197
# compute temperature
193198
TEMPERATURE = 0
194199
for n, c in enumerate(DCOEF):

0 commit comments

Comments
 (0)