Skip to content

Correct Missing Type Annotations #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions adafruit_ina260.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

# imports

try:
import typing # pylint: disable=unused-import
from busio import I2C
except ImportError:
pass

__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_INA260.git"

Expand Down Expand Up @@ -101,7 +107,7 @@ class ConversionTime:
TIME_8_244_ms = const(0x7)

@staticmethod
def get_seconds(time_enum):
def get_seconds(time_enum: int) -> float:
"""Retrieve the time in seconds giving value read from register"""
conv_dict = {
0: 140e-6,
Expand Down Expand Up @@ -151,7 +157,7 @@ class AveragingCount:
COUNT_1024 = const(0x7)

@staticmethod
def get_averaging_count(avg_count):
def get_averaging_count(avg_count: int) -> float:
"""Retrieve the number of measurements giving value read from register"""
conv_dict = {0: 1, 1: 4, 2: 16, 3: 64, 4: 128, 5: 256, 6: 512, 7: 1024}
return conv_dict[avg_count]
Expand All @@ -164,25 +170,24 @@ class INA260:
"""Driver for the INA260 power and current sensor.

:param ~busio.I2C i2c_bus: The I2C bus the INA260 is connected to.
:param address: The I2C device address for the sensor. Default is ``0x40``.
:param int address: The I2C device address for the sensor. Default is ``0x40``.

"""

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

if self._manufacturer_id != self.TEXAS_INSTRUMENT_ID:
raise RuntimeError(
"Failed to find Texas Instrument ID, read {} while expected {}"
" - check your wiring!".format(
self._manufacturer_id, self.TEXAS_INSTRUMENT_ID
)
"Failed to find Texas Instrument ID, read "
+ f"{self._manufacturer_id} while expected {self.TEXAS_INSTRUMENT_ID}"
" - check your wiring!"
)

if self._device_id != self.INA260_ID:
raise RuntimeError(
"Failed to find INA260 ID, read {} while expected {}"
" - check your wiring!".format(self._device_id, self.INA260_ID)
"Failed to find INA260 ID, read {self._device_id} while expected {self.INA260_ID}"
" - check your wiring!"
)

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

@property
def current(self):
def current(self) -> float:
"""The current (between V+ and V-) in mA"""
if self.mode == Mode.TRIGGERED:
while self._conversion_ready_flag == 0:
pass
return self._raw_current * 1.25

@property
def voltage(self):
def voltage(self) -> float:
"""The bus voltage in V"""
if self.mode == Mode.TRIGGERED:
while self._conversion_ready_flag == 0:
pass
return self._raw_voltage * 0.00125

@property
def power(self):
def power(self) -> int:
"""The power being delivered to the load in mW"""
if self.mode == Mode.TRIGGERED:
while self._conversion_ready_flag == 0:
Expand Down