20
20
21
21
# imports
22
22
23
+ try :
24
+ import typing # pylint: disable=unused-import
25
+ from busio import I2C
26
+ except ImportError :
27
+ pass
28
+
23
29
__version__ = "0.0.0+auto.0"
24
30
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_INA260.git"
25
31
@@ -101,7 +107,7 @@ class ConversionTime:
101
107
TIME_8_244_ms = const (0x7 )
102
108
103
109
@staticmethod
104
- def get_seconds (time_enum ) :
110
+ def get_seconds (time_enum : int ) -> float :
105
111
"""Retrieve the time in seconds giving value read from register"""
106
112
conv_dict = {
107
113
0 : 140e-6 ,
@@ -151,7 +157,7 @@ class AveragingCount:
151
157
COUNT_1024 = const (0x7 )
152
158
153
159
@staticmethod
154
- def get_averaging_count (avg_count ) :
160
+ def get_averaging_count (avg_count : int ) -> float :
155
161
"""Retrieve the number of measurements giving value read from register"""
156
162
conv_dict = {0 : 1 , 1 : 4 , 2 : 16 , 3 : 64 , 4 : 128 , 5 : 256 , 6 : 512 , 7 : 1024 }
157
163
return conv_dict [avg_count ]
@@ -164,25 +170,24 @@ class INA260:
164
170
"""Driver for the INA260 power and current sensor.
165
171
166
172
:param ~busio.I2C i2c_bus: The I2C bus the INA260 is connected to.
167
- :param address: The I2C device address for the sensor. Default is ``0x40``.
173
+ :param int address: The I2C device address for the sensor. Default is ``0x40``.
168
174
169
175
"""
170
176
171
- def __init__ (self , i2c_bus , address = 0x40 ):
177
+ def __init__ (self , i2c_bus : I2C , address : int = 0x40 ) -> None :
172
178
self .i2c_device = i2cdevice .I2CDevice (i2c_bus , address )
173
179
174
180
if self ._manufacturer_id != self .TEXAS_INSTRUMENT_ID :
175
181
raise RuntimeError (
176
- "Failed to find Texas Instrument ID, read {} while expected {}"
177
- " - check your wiring!" .format (
178
- self ._manufacturer_id , self .TEXAS_INSTRUMENT_ID
179
- )
182
+ "Failed to find Texas Instrument ID, read "
183
+ + f"{ self ._manufacturer_id } while expected { self .TEXAS_INSTRUMENT_ID } "
184
+ " - check your wiring!"
180
185
)
181
186
182
187
if self ._device_id != self .INA260_ID :
183
188
raise RuntimeError (
184
- "Failed to find INA260 ID, read {} while expected {}"
185
- " - check your wiring!" . format ( self . _device_id , self . INA260_ID )
189
+ "Failed to find INA260 ID, read {self._device_id } while expected {self.INA260_ID }"
190
+ " - check your wiring!"
186
191
)
187
192
188
193
_raw_current = ROUnaryStruct (_REG_CURRENT , ">h" )
@@ -280,23 +285,23 @@ def __init__(self, i2c_bus, address=0x40):
280
285
"""Device revision identification bits"""
281
286
282
287
@property
283
- def current (self ):
288
+ def current (self ) -> float :
284
289
"""The current (between V+ and V-) in mA"""
285
290
if self .mode == Mode .TRIGGERED :
286
291
while self ._conversion_ready_flag == 0 :
287
292
pass
288
293
return self ._raw_current * 1.25
289
294
290
295
@property
291
- def voltage (self ):
296
+ def voltage (self ) -> float :
292
297
"""The bus voltage in V"""
293
298
if self .mode == Mode .TRIGGERED :
294
299
while self ._conversion_ready_flag == 0 :
295
300
pass
296
301
return self ._raw_voltage * 0.00125
297
302
298
303
@property
299
- def power (self ):
304
+ def power (self ) -> int :
300
305
"""The power being delivered to the load in mW"""
301
306
if self .mode == Mode .TRIGGERED :
302
307
while self ._conversion_ready_flag == 0 :
0 commit comments