41
41
from adafruit_register .i2c_bits import RWBits
42
42
from adafruit_register .i2c_bit import ROBit
43
43
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
+
44
51
__version__ = "0.0.0+auto.0"
45
52
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MCP9808.git"
46
53
@@ -74,9 +81,9 @@ class MCP9808:
74
81
You could set the MCP9808 with different temperature limits and compare them with the
75
82
ambient temperature Ta
76
83
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
80
87
81
88
To get this value, you will need to read the temperature, and then access the attribute
82
89
@@ -120,7 +127,7 @@ class MCP9808:
120
127
"""True when the temperature is below the currently
121
128
set lower temperature. False Otherwise"""
122
129
123
- def __init__ (self , i2c_bus , address = _MCP9808_DEFAULT_ADDRESS ):
130
+ def __init__ (self , i2c_bus : I2C , address : int = _MCP9808_DEFAULT_ADDRESS ) -> None :
124
131
self .i2c_device = I2CDevice (i2c_bus , address )
125
132
126
133
# 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):
143
150
)
144
151
145
152
@property
146
- def temperature (self ):
153
+ def temperature (self ) -> float :
147
154
"""Temperature in Celsius. Read-only."""
148
155
self .buf [0 ] = _MCP9808_REG__TEMP
149
156
with self .i2c_device as i2c :
150
157
i2c .write_then_readinto (self .buf , self .buf , out_end = 1 , in_start = 1 )
151
158
152
159
return self ._temp_conv ()
153
160
154
- def _temp_conv (self ):
161
+ def _temp_conv (self ) -> float :
155
162
"""Internal function to convert temperature given by the sensor"""
156
163
# Clear flags from the value
157
164
self .buf [1 ] = self .buf [1 ] & 0x1F
@@ -160,7 +167,9 @@ def _temp_conv(self):
160
167
return (self .buf [1 ] * 16 + self .buf [2 ] / 16.0 ) - 256
161
168
return self .buf [1 ] * 16 + self .buf [2 ] / 16.0
162
169
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 :
164
173
"""Internal function to setup limit temperature
165
174
166
175
:param int temp: temperature limit
@@ -187,54 +196,54 @@ def _limit_temperatures(self, temp, t_address=0x02):
187
196
with self .i2c_device as i2c :
188
197
i2c .write (self .buf )
189
198
190
- def _get_temperature (self , address ) :
199
+ def _get_temperature (self , address : Literal [ 0x02 , 0x03 , 0x04 ]) -> float :
191
200
self .buf [0 ] = address
192
201
with self .i2c_device as i2c :
193
202
i2c .write_then_readinto (self .buf , self .buf , out_end = 1 , in_start = 1 )
194
203
195
204
return self ._temp_conv ()
196
205
197
- def _set_temperature (self , temp , address ) :
206
+ def _set_temperature (self , temp : int , address : Literal [ 0x02 , 0x03 , 0x04 ]) -> None :
198
207
self ._limit_temperatures (temp , address )
199
208
200
209
@property
201
- def upper_temperature (self ):
210
+ def upper_temperature (self ) -> float :
202
211
"""Upper alarm temperature in Celsius"""
203
212
204
213
return self ._get_temperature (_MCP9808_REG_UPPER_TEMP )
205
214
206
215
@upper_temperature .setter
207
- def upper_temperature (self , temp ) :
216
+ def upper_temperature (self , temp : int ) -> None :
208
217
"""Setup Upper temperature"""
209
218
210
219
self ._limit_temperatures (temp , _MCP9808_REG_UPPER_TEMP )
211
220
212
221
@property
213
- def lower_temperature (self ):
222
+ def lower_temperature (self ) -> float :
214
223
"""Lower alarm temperature in Celsius"""
215
224
216
225
return self ._get_temperature (_MCP9808_REG_LOWER_TEMP )
217
226
218
227
@lower_temperature .setter
219
- def lower_temperature (self , temp ) :
228
+ def lower_temperature (self , temp : int ) -> None :
220
229
"""Setup Lower temperature"""
221
230
222
231
self ._limit_temperatures (temp , _MCP9808_REG_LOWER_TEMP )
223
232
224
233
@property
225
- def critical_temperature (self ):
234
+ def critical_temperature (self ) -> float :
226
235
"""Critical alarm temperature in Celsius"""
227
236
228
237
return self ._get_temperature (_MCP9808_REG_CRITICAL_TEMP )
229
238
230
239
@critical_temperature .setter
231
- def critical_temperature (self , temp ) :
240
+ def critical_temperature (self , temp : int ) -> None :
232
241
"""Setup Critical temperature"""
233
242
234
243
self ._limit_temperatures (temp , _MCP9808_REG_CRITICAL_TEMP )
235
244
236
245
@property
237
- def resolution (self ):
246
+ def resolution (self ) -> Literal [ 0 , 1 , 2 , 3 ] :
238
247
"""Temperature Resolution in Celsius
239
248
240
249
======= ============ ==============
@@ -251,7 +260,7 @@ def resolution(self):
251
260
return self ._MCP9808_REG_RESOLUTION_SET
252
261
253
262
@resolution .setter
254
- def resolution (self , resol_value = 3 ) :
263
+ def resolution (self , resol_value : Literal [ 0 , 1 , 2 , 3 ] = 3 ) -> None :
255
264
"""Setup Critical temperature"""
256
265
257
266
self ._MCP9808_REG_RESOLUTION_SET = resol_value # pylint: disable=invalid-name
0 commit comments