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