Skip to content

Commit b0f63e2

Browse files
committed
annotated __init__, resistance(self), temperature(self)
1 parent 9f7aa00 commit b0f63e2

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

adafruit_thermistor.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939

4040
import math
4141
import analogio
42-
import microcontroller
42+
try:
43+
import typing # pylint: disable=unused-import
44+
import microcontroller
45+
except ImportError:
46+
pass
4347

4448
__version__ = "0.0.0-auto.0"
4549
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Thermistor.git"
@@ -86,14 +90,14 @@ class Thermistor:
8690

8791
def __init__(
8892
self,
89-
pin: microcontroller.pin,
93+
pin: microcontroller.Pin,
9094
series_resistor: int,
9195
nominal_resistance: int,
9296
nominal_temperature: int,
9397
b_coefficient: int,
9498
*,
9599
high_side: bool = True
96-
):
100+
) -> None:
97101
# pylint: disable=too-many-arguments
98102
self.pin = analogio.AnalogIn(pin)
99103
self.series_resistor = series_resistor
@@ -103,7 +107,7 @@ def __init__(
103107
self.high_side = high_side
104108

105109
@property
106-
def resistance(self):
110+
def resistance(self) -> float:
107111
"""The resistance of the thermistor in Ohms"""
108112
if self.high_side:
109113
# Thermistor connected from analog input to high logic level.
@@ -116,7 +120,7 @@ def resistance(self):
116120
return reading
117121

118122
@property
119-
def temperature(self):
123+
def temperature(self) -> float:
120124
"""The temperature of the thermistor in Celsius"""
121125
steinhart = self.resistance / self.nominal_resistance # (R/Ro)
122126
steinhart = math.log(steinhart) # ln(R/Ro)

0 commit comments

Comments
 (0)