4141from adafruit_register .i2c_bits import RWBits
4242from adafruit_register .i2c_bit import ROBit
4343
44+ try :
45+ import typing # pylint: disable=unused-import
46+ from typing_extensions import Literal
47+ from busio import I2C
48+ except ImportError :
49+ pass
50+
4451__version__ = "0.0.0+auto.0"
4552__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MCP9808.git"
4653
@@ -74,9 +81,9 @@ class MCP9808:
7481 You could set the MCP9808 with different temperature limits and compare them with the
7582 ambient temperature Ta
7683
77- - above_ct this value will be set to `True` when Ta is above this limit
78- - above_ut : this value will be set to `True` when Ta is above this limit
79- - below_lt : this value will be set to `True` when Ta is below this limit
84+ - above_critical: this value will be set to `True` when Ta is above this limit
85+ - above_upper : this value will be set to `True` when Ta is above this limit
86+ - below_lower : this value will be set to `True` when Ta is below this limit
8087
8188 To get this value, you will need to read the temperature, and then access the attribute
8289
@@ -120,7 +127,7 @@ class MCP9808:
120127 """True when the temperature is below the currently
121128 set lower temperature. False Otherwise"""
122129
123- def __init__ (self , i2c_bus , address = _MCP9808_DEFAULT_ADDRESS ):
130+ def __init__ (self , i2c_bus : I2C , address : int = _MCP9808_DEFAULT_ADDRESS ) -> None :
124131 self .i2c_device = I2CDevice (i2c_bus , address )
125132
126133 # Verify the manufacturer and device ids to ensure we are talking to
@@ -143,15 +150,15 @@ def __init__(self, i2c_bus, address=_MCP9808_DEFAULT_ADDRESS):
143150 )
144151
145152 @property
146- def temperature (self ):
153+ def temperature (self ) -> float :
147154 """Temperature in Celsius. Read-only."""
148155 self .buf [0 ] = _MCP9808_REG__TEMP
149156 with self .i2c_device as i2c :
150157 i2c .write_then_readinto (self .buf , self .buf , out_end = 1 , in_start = 1 )
151158
152159 return self ._temp_conv ()
153160
154- def _temp_conv (self ):
161+ def _temp_conv (self ) -> float :
155162 """Internal function to convert temperature given by the sensor"""
156163 # Clear flags from the value
157164 self .buf [1 ] = self .buf [1 ] & 0x1F
@@ -160,7 +167,9 @@ def _temp_conv(self):
160167 return (self .buf [1 ] * 16 + self .buf [2 ] / 16.0 ) - 256
161168 return self .buf [1 ] * 16 + self .buf [2 ] / 16.0
162169
163- def _limit_temperatures (self , temp , t_address = 0x02 ):
170+ def _limit_temperatures (
171+ self , temp : int , t_address : Literal [0x02 , 0x03 , 0x04 ] = 0x02
172+ ) -> None :
164173 """Internal function to setup limit temperature
165174
166175 :param int temp: temperature limit
@@ -187,54 +196,54 @@ def _limit_temperatures(self, temp, t_address=0x02):
187196 with self .i2c_device as i2c :
188197 i2c .write (self .buf )
189198
190- def _get_temperature (self , address ) :
199+ def _get_temperature (self , address : Literal [ 0x02 , 0x03 , 0x04 ]) -> float :
191200 self .buf [0 ] = address
192201 with self .i2c_device as i2c :
193202 i2c .write_then_readinto (self .buf , self .buf , out_end = 1 , in_start = 1 )
194203
195204 return self ._temp_conv ()
196205
197- def _set_temperature (self , temp , address ) :
206+ def _set_temperature (self , temp : int , address : Literal [ 0x02 , 0x03 , 0x04 ]) -> None :
198207 self ._limit_temperatures (temp , address )
199208
200209 @property
201- def upper_temperature (self ):
210+ def upper_temperature (self ) -> float :
202211 """Upper alarm temperature in Celsius"""
203212
204213 return self ._get_temperature (_MCP9808_REG_UPPER_TEMP )
205214
206215 @upper_temperature .setter
207- def upper_temperature (self , temp ) :
216+ def upper_temperature (self , temp : int ) -> None :
208217 """Setup Upper temperature"""
209218
210219 self ._limit_temperatures (temp , _MCP9808_REG_UPPER_TEMP )
211220
212221 @property
213- def lower_temperature (self ):
222+ def lower_temperature (self ) -> float :
214223 """Lower alarm temperature in Celsius"""
215224
216225 return self ._get_temperature (_MCP9808_REG_LOWER_TEMP )
217226
218227 @lower_temperature .setter
219- def lower_temperature (self , temp ) :
228+ def lower_temperature (self , temp : int ) -> None :
220229 """Setup Lower temperature"""
221230
222231 self ._limit_temperatures (temp , _MCP9808_REG_LOWER_TEMP )
223232
224233 @property
225- def critical_temperature (self ):
234+ def critical_temperature (self ) -> float :
226235 """Critical alarm temperature in Celsius"""
227236
228237 return self ._get_temperature (_MCP9808_REG_CRITICAL_TEMP )
229238
230239 @critical_temperature .setter
231- def critical_temperature (self , temp ) :
240+ def critical_temperature (self , temp : int ) -> None :
232241 """Setup Critical temperature"""
233242
234243 self ._limit_temperatures (temp , _MCP9808_REG_CRITICAL_TEMP )
235244
236245 @property
237- def resolution (self ):
246+ def resolution (self ) -> Literal [ 0 , 1 , 2 , 3 ] :
238247 """Temperature Resolution in Celsius
239248
240249 ======= ============ ==============
@@ -251,7 +260,7 @@ def resolution(self):
251260 return self ._MCP9808_REG_RESOLUTION_SET
252261
253262 @resolution .setter
254- def resolution (self , resol_value = 3 ) :
263+ def resolution (self , resol_value : Literal [ 0 , 1 , 2 , 3 ] = 3 ) -> None :
255264 """Setup Critical temperature"""
256265
257266 self ._MCP9808_REG_RESOLUTION_SET = resol_value # pylint: disable=invalid-name
0 commit comments