32
32
33
33
from adafruit_bus_device .spi_device import SPIDevice
34
34
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
+
35
42
__version__ = "0.0.0+auto.0"
36
43
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MAX31855.git"
37
44
@@ -71,11 +78,11 @@ class MAX31855:
71
78
temperature = sensor.temperature
72
79
"""
73
80
74
- def __init__ (self , spi , cs ) :
81
+ def __init__ (self , spi : SPI , cs : DigitalInOut ) -> None :
75
82
self .spi_device = SPIDevice (spi , cs )
76
83
self .data = bytearray (4 )
77
84
78
- def _read (self , internal = False ):
85
+ def _read (self , internal : bool = False ) -> int :
79
86
with self .spi_device as spi :
80
87
spi .readinto (self .data ) # pylint: disable=no-member
81
88
if self .data [3 ] & 0x01 :
@@ -94,17 +101,17 @@ def _read(self, internal=False):
94
101
return temp
95
102
96
103
@property
97
- def temperature (self ):
104
+ def temperature (self ) -> float :
98
105
"""Thermocouple temperature in degrees Celsius."""
99
106
return self ._read () / 4
100
107
101
108
@property
102
- def reference_temperature (self ):
109
+ def reference_temperature (self ) -> float :
103
110
"""Internal reference temperature in degrees Celsius."""
104
111
return self ._read (True ) * 0.0625
105
112
106
113
@property
107
- def temperature_NIST (self ):
114
+ def temperature_NIST (self ) -> float :
108
115
"""
109
116
Thermocouple temperature in degrees Celsius, computed using
110
117
raw voltages and NIST approximation for Type K, see:
@@ -186,9 +193,7 @@ def temperature_NIST(self):
186
193
- 3.110810e-08 ,
187
194
)
188
195
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 } " )
192
197
# compute temperature
193
198
TEMPERATURE = 0
194
199
for n , c in enumerate (DCOEF ):
0 commit comments