3333from adafruit_register .i2c_bits import ROBits , RWBits
3434from adafruit_register .i2c_bit import ROBit
3535
36+ try :
37+ import typing # pylint: disable=unused-import
38+ from busio import I2C
39+ except ImportError :
40+ pass
41+
3642__version__ = "0.0.0+auto.0"
3743__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_INA219.git"
3844
@@ -105,7 +111,7 @@ class Mode:
105111# pylint: enable=too-few-public-methods
106112
107113
108- def _to_signed (num ) :
114+ def _to_signed (num : int ) -> int :
109115 if num > 0x7FFF :
110116 num -= 0x10000
111117 return num
@@ -145,7 +151,7 @@ class INA219:
145151 # raw_current RO : Current register (not scaled)
146152 # calibration RW : calibration register (note: value is cached)
147153
148- def __init__ (self , i2c_bus , addr = 0x40 ):
154+ def __init__ (self , i2c_bus : I2C , addr : int = 0x40 ) -> None :
149155 self .i2c_device = I2CDevice (i2c_bus , addr )
150156 self .i2c_addr = addr
151157
@@ -179,32 +185,32 @@ def __init__(self, i2c_bus, addr=0x40):
179185 _raw_calibration = UnaryStruct (_REG_CALIBRATION , ">H" )
180186
181187 @property
182- def calibration (self ):
188+ def calibration (self ) -> int :
183189 """Calibration register (cached value)"""
184190 return self ._cal_value # return cached value
185191
186192 @calibration .setter
187- def calibration (self , cal_value ) :
193+ def calibration (self , cal_value : int ) -> None :
188194 self ._cal_value = (
189195 cal_value # value is cached for ``current`` and ``power`` properties
190196 )
191197 self ._raw_calibration = self ._cal_value
192198
193199 @property
194- def shunt_voltage (self ):
200+ def shunt_voltage (self ) -> float :
195201 """The shunt voltage (between V+ and V-) in Volts (so +-.327V)"""
196202 # The least signficant bit is 10uV which is 0.00001 volts
197203 return self .raw_shunt_voltage * 0.00001
198204
199205 @property
200- def bus_voltage (self ):
206+ def bus_voltage (self ) -> float :
201207 """The bus voltage (between V- and GND) in Volts"""
202208 # Shift to the right 3 to drop CNVR and OVF and multiply by LSB
203209 # Each least signficant bit is 4mV
204210 return self .raw_bus_voltage * 0.004
205211
206212 @property
207- def current (self ):
213+ def current (self ) -> float :
208214 """The current through the shunt resistor in milliamps."""
209215 # Sometimes a sharp load will reset the INA219, which will
210216 # reset the cal register, meaning CURRENT and POWER will
@@ -215,7 +221,7 @@ def current(self):
215221 return self .raw_current * self ._current_lsb
216222
217223 @property
218- def power (self ):
224+ def power (self ) -> float :
219225 """The power through the load in Watt."""
220226 # Sometimes a sharp load will reset the INA219, which will
221227 # reset the cal register, meaning CURRENT and POWER will
@@ -225,7 +231,7 @@ def power(self):
225231 # Now we can safely read the CURRENT register!
226232 return self .raw_power * self ._power_lsb
227233
228- def set_calibration_32V_2A (self ): # pylint: disable=invalid-name
234+ def set_calibration_32V_2A (self ) -> None : # pylint: disable=invalid-name
229235 """Configures to INA219 to be able to measure up to 32V and 2A of current. Counter
230236 overflow occurs at 3.2A.
231237
@@ -306,7 +312,7 @@ def set_calibration_32V_2A(self): # pylint: disable=invalid-name
306312 self .shunt_adc_resolution = ADCResolution .ADCRES_12BIT_1S
307313 self .mode = Mode .SANDBVOLT_CONTINUOUS
308314
309- def set_calibration_32V_1A (self ): # pylint: disable=invalid-name
315+ def set_calibration_32V_1A (self ) -> None : # pylint: disable=invalid-name
310316 """Configures to INA219 to be able to measure up to 32V and 1A of current. Counter overflow
311317 occurs at 1.3A.
312318
@@ -388,7 +394,7 @@ def set_calibration_32V_1A(self): # pylint: disable=invalid-name
388394 self .shunt_adc_resolution = ADCResolution .ADCRES_12BIT_1S
389395 self .mode = Mode .SANDBVOLT_CONTINUOUS
390396
391- def set_calibration_16V_400mA (self ): # pylint: disable=invalid-name
397+ def set_calibration_16V_400mA (self ) -> None : # pylint: disable=invalid-name
392398 """Configures to INA219 to be able to measure up to 16V and 400mA of current. Counter
393399 overflow occurs at 1.6A.
394400
@@ -471,7 +477,7 @@ def set_calibration_16V_400mA(self): # pylint: disable=invalid-name
471477 self .shunt_adc_resolution = ADCResolution .ADCRES_12BIT_1S
472478 self .mode = Mode .SANDBVOLT_CONTINUOUS
473479
474- def set_calibration_16V_5A (self ): # pylint: disable=invalid-name
480+ def set_calibration_16V_5A (self ) -> None : # pylint: disable=invalid-name
475481 """Configures to INA219 to be able to measure up to 16V and 5000mA of current. Counter
476482 overflow occurs at 8.0A.
477483
0 commit comments