Skip to content

Commit fe721fc

Browse files
committed
Correct Missing Type Annotations
1 parent 61077df commit fe721fc

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

adafruit_ina260.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
# imports
2222

23+
try:
24+
from board import I2C
25+
except ImportError:
26+
pass
27+
2328
__version__ = "0.0.0+auto.0"
2429
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_INA260.git"
2530

@@ -101,7 +106,7 @@ class ConversionTime:
101106
TIME_8_244_ms = const(0x7)
102107

103108
@staticmethod
104-
def get_seconds(time_enum):
109+
def get_seconds(time_enum: int) -> float:
105110
"""Retrieve the time in seconds giving value read from register"""
106111
conv_dict = {
107112
0: 140e-6,
@@ -151,7 +156,7 @@ class AveragingCount:
151156
COUNT_1024 = const(0x7)
152157

153158
@staticmethod
154-
def get_averaging_count(avg_count):
159+
def get_averaging_count(avg_count: int) -> float:
155160
"""Retrieve the number of measurements giving value read from register"""
156161
conv_dict = {0: 1, 1: 4, 2: 16, 3: 64, 4: 128, 5: 256, 6: 512, 7: 1024}
157162
return conv_dict[avg_count]
@@ -168,21 +173,19 @@ class INA260:
168173
169174
"""
170175

171-
def __init__(self, i2c_bus, address=0x40):
176+
def __init__(self, i2c_bus: I2C(), address: int = 0x40) -> None:
172177
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)
173178

174179
if self._manufacturer_id != self.TEXAS_INSTRUMENT_ID:
175180
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!"
180183
)
181184

182185
if self._device_id != self.INA260_ID:
183186
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!"
186189
)
187190

188191
_raw_current = ROUnaryStruct(_REG_CURRENT, ">h")
@@ -280,23 +283,23 @@ def __init__(self, i2c_bus, address=0x40):
280283
"""Device revision identification bits"""
281284

282285
@property
283-
def current(self):
286+
def current(self) -> float:
284287
"""The current (between V+ and V-) in mA"""
285288
if self.mode == Mode.TRIGGERED:
286289
while self._conversion_ready_flag == 0:
287290
pass
288291
return self._raw_current * 1.25
289292

290293
@property
291-
def voltage(self):
294+
def voltage(self) -> float:
292295
"""The bus voltage in V"""
293296
if self.mode == Mode.TRIGGERED:
294297
while self._conversion_ready_flag == 0:
295298
pass
296299
return self._raw_voltage * 0.00125
297300

298301
@property
299-
def power(self):
302+
def power(self) -> float:
300303
"""The power being delivered to the load in mW"""
301304
if self.mode == Mode.TRIGGERED:
302305
while self._conversion_ready_flag == 0:

0 commit comments

Comments
 (0)