Skip to content

Commit 23466fa

Browse files
authored
Merge pull request #20 from tcfranks/main
Correct Missing Type Annotations
2 parents 61077df + 3c5ba58 commit 23466fa

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

adafruit_ina260.py

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

2121
# imports
2222

23+
try:
24+
import typing # pylint: disable=unused-import
25+
from busio import I2C
26+
except ImportError:
27+
pass
28+
2329
__version__ = "0.0.0+auto.0"
2430
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_INA260.git"
2531

@@ -101,7 +107,7 @@ class ConversionTime:
101107
TIME_8_244_ms = const(0x7)
102108

103109
@staticmethod
104-
def get_seconds(time_enum):
110+
def get_seconds(time_enum: int) -> float:
105111
"""Retrieve the time in seconds giving value read from register"""
106112
conv_dict = {
107113
0: 140e-6,
@@ -151,7 +157,7 @@ class AveragingCount:
151157
COUNT_1024 = const(0x7)
152158

153159
@staticmethod
154-
def get_averaging_count(avg_count):
160+
def get_averaging_count(avg_count: int) -> float:
155161
"""Retrieve the number of measurements giving value read from register"""
156162
conv_dict = {0: 1, 1: 4, 2: 16, 3: 64, 4: 128, 5: 256, 6: 512, 7: 1024}
157163
return conv_dict[avg_count]
@@ -164,25 +170,24 @@ class INA260:
164170
"""Driver for the INA260 power and current sensor.
165171
166172
: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``.
168174
169175
"""
170176

171-
def __init__(self, i2c_bus, address=0x40):
177+
def __init__(self, i2c_bus: I2C, address: int = 0x40) -> None:
172178
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)
173179

174180
if self._manufacturer_id != self.TEXAS_INSTRUMENT_ID:
175181
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!"
180185
)
181186

182187
if self._device_id != self.INA260_ID:
183188
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!"
186191
)
187192

188193
_raw_current = ROUnaryStruct(_REG_CURRENT, ">h")
@@ -280,23 +285,23 @@ def __init__(self, i2c_bus, address=0x40):
280285
"""Device revision identification bits"""
281286

282287
@property
283-
def current(self):
288+
def current(self) -> float:
284289
"""The current (between V+ and V-) in mA"""
285290
if self.mode == Mode.TRIGGERED:
286291
while self._conversion_ready_flag == 0:
287292
pass
288293
return self._raw_current * 1.25
289294

290295
@property
291-
def voltage(self):
296+
def voltage(self) -> float:
292297
"""The bus voltage in V"""
293298
if self.mode == Mode.TRIGGERED:
294299
while self._conversion_ready_flag == 0:
295300
pass
296301
return self._raw_voltage * 0.00125
297302

298303
@property
299-
def power(self):
304+
def power(self) -> int:
300305
"""The power being delivered to the load in mW"""
301306
if self.mode == Mode.TRIGGERED:
302307
while self._conversion_ready_flag == 0:

0 commit comments

Comments
 (0)