Skip to content

Commit 223ee85

Browse files
authored
Merge pull request #6 from tcfranks/main
Add Missing Type Annotations
2 parents 877d9f1 + 3c32695 commit 223ee85

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

adafruit_ds1841.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
from adafruit_register.i2c_struct_array import StructArray
3434
from adafruit_register.i2c_bit import RWBit
3535

36+
try:
37+
import typing # pylint: disable=unused-import
38+
from busio import I2C
39+
except ImportError:
40+
pass
3641

3742
_DS1841_IVR = 0x00
3843
_DS1841_CR0 = 0x02
@@ -72,7 +77,7 @@ class DS1841:
7277

7378
_lut = StructArray(_DS1841_LUT, ">B", 72)
7479

75-
def __init__(self, i2c_bus, address=_DS1841_DEFAULT_ADDRESS):
80+
def __init__(self, i2c_bus: I2C, address: int = _DS1841_DEFAULT_ADDRESS) -> None:
7681
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
7782

7883
self._disable_save_to_eeprom = True # turn off eeprom updates to IV and CR0
@@ -85,28 +90,28 @@ def __init__(self, i2c_bus, address=_DS1841_DEFAULT_ADDRESS):
8590
self._update_mode = True
8691

8792
@property
88-
def wiper(self):
93+
def wiper(self) -> int:
8994
"""The value of the potentionmeter's wiper.
9095
:param wiper_value: The value from 0-127 to set the wiper to.
9196
"""
9297
return self._wiper_register
9398

9499
@wiper.setter
95-
def wiper(self, value):
100+
def wiper(self, value: int) -> None:
96101
if value > 127:
97102
raise AttributeError("wiper must be from 0-127")
98103
self._wiper_register = value
99104

100105
@property
101-
def wiper_default(self):
106+
def wiper_default(self) -> int:
102107
"""Sets the wiper's default value and current value to the given value
103108
:param new_default: The value from 0-127 to set as the wiper's default.
104109
"""
105110

106111
return self._initial_value_register
107112

108113
@wiper_default.setter
109-
def wiper_default(self, value):
114+
def wiper_default(self, value: int) -> None:
110115
if value > 127:
111116
raise AttributeError("initial_value must be from 0-127")
112117
self._disable_save_to_eeprom = False
@@ -122,32 +127,32 @@ def wiper_default(self, value):
122127
self._update_mode = True
123128

124129
@property
125-
def temperature(self):
126-
"""The current temperature in degrees celcius"""
130+
def temperature(self) -> int:
131+
"""The current temperature in degrees celsius"""
127132
return self._temperature_register
128133

129134
@property
130-
def voltage(self):
135+
def voltage(self) -> float:
131136
"""The current voltage between VCC and GND"""
132137
return self._voltage_register * _DS1841_VCC_LSB
133138

134139
######## LUTS on LUTS on LUTS
135140
@property
136-
def lut_mode_enabled(self):
141+
def lut_mode_enabled(self) -> bool:
137142
"""Enables LUT mode. LUT mode takes sets the value of the Wiper based on the entry in a
138143
72-entry Look Up Table. The LUT entry is selected using the `lut_selection`
139144
property to set an index from 0-71
140145
"""
141146
return self._lut_mode_enabled
142147

143148
@lut_mode_enabled.setter
144-
def lut_mode_enabled(self, value):
149+
def lut_mode_enabled(self, value: bool) -> None:
145150
self._manual_lut_address = value
146151
self._update_mode = True
147152
self._manual_wiper_value = not value
148153
self._lut_mode_enabled = value
149154

150-
def set_lut(self, index, value):
155+
def set_lut(self, index: int, value: int) -> None:
151156
"""Set the value of an entry in the Look Up Table.
152157
:param index: The index of the entry to set, from 0-71.
153158
:param value: The value to set at the given index. The `wiper` will be set to this
@@ -160,7 +165,7 @@ def set_lut(self, index, value):
160165
sleep(0.020)
161166

162167
@property
163-
def lut_selection(self):
168+
def lut_selection(self) -> int:
164169
"""Choose the entry in the Look Up Table to use to set the wiper.
165170
:param index: The index of the entry to use, from 0-71.
166171
"""
@@ -171,7 +176,7 @@ def lut_selection(self):
171176
return self._lut_address - _DS1841_LUT
172177

173178
@lut_selection.setter
174-
def lut_selection(self, value):
179+
def lut_selection(self, value: int) -> None:
175180
if value > 71 or value < 0:
176181
raise IndexError("lut_selection value must be from 0-71")
177182
self._lut_address = value + _DS1841_LUT

0 commit comments

Comments
 (0)