From fe721fcd52777d1475aa584485e680499a03d373 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 25 Aug 2022 11:43:47 -0400 Subject: [PATCH 1/8] Correct Missing Type Annotations --- adafruit_ina260.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/adafruit_ina260.py b/adafruit_ina260.py index 2efe15a..29f6105 100644 --- a/adafruit_ina260.py +++ b/adafruit_ina260.py @@ -20,6 +20,11 @@ # imports +try: + from board import I2C +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_INA260.git" @@ -101,7 +106,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, @@ -151,7 +156,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] @@ -168,21 +173,19 @@ class INA260: """ - 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 - ) + f"Failed to find Texas Instrument ID, read {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") @@ -280,7 +283,7 @@ 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: @@ -288,7 +291,7 @@ def current(self): 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: @@ -296,7 +299,7 @@ def voltage(self): return self._raw_voltage * 0.00125 @property - def power(self): + def power(self) -> float: """The power being delivered to the load in mW""" if self.mode == Mode.TRIGGERED: while self._conversion_ready_flag == 0: From 07b23e8712f13e4adcf396b0964145ff1eb1c8d2 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 25 Aug 2022 11:52:23 -0400 Subject: [PATCH 2/8] Correct Missing Type Annotations --- adafruit_ina260.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_ina260.py b/adafruit_ina260.py index 29f6105..441cc00 100644 --- a/adafruit_ina260.py +++ b/adafruit_ina260.py @@ -178,7 +178,8 @@ def __init__(self, i2c_bus: I2C(), address: int = 0x40) -> None: if self._manufacturer_id != self.TEXAS_INSTRUMENT_ID: raise RuntimeError( - f"Failed to find Texas Instrument ID, read {self._manufacturer_id} while expected {self.TEXAS_INSTRUMENT_ID}" + f"Failed to find Texas Instrument ID, read {self._manufacturer_id} while expected " + f"{self.TEXAS_INSTRUMENT_ID}" " - check your wiring!" ) From 2ba1e2a8887dad6151a849ab2f6338cfaec3d61b Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 25 Aug 2022 11:58:48 -0400 Subject: [PATCH 3/8] Correct Missing Type Annotations --- adafruit_ina260.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_ina260.py b/adafruit_ina260.py index 441cc00..9892bf4 100644 --- a/adafruit_ina260.py +++ b/adafruit_ina260.py @@ -178,8 +178,8 @@ def __init__(self, i2c_bus: I2C(), address: int = 0x40) -> None: if self._manufacturer_id != self.TEXAS_INSTRUMENT_ID: raise RuntimeError( - f"Failed to find Texas Instrument ID, read {self._manufacturer_id} while expected " - f"{self.TEXAS_INSTRUMENT_ID}" + "Failed to find Texas Instrument ID, read " + + f"{self._manufacturer_id} while expected {self.TEXAS_INSTRUMENT_ID}" " - check your wiring!" ) From 83e200f504ef1e523f1e90565ec49942833a7f85 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 25 Aug 2022 12:03:56 -0400 Subject: [PATCH 4/8] Correct Missing Type Annotations --- adafruit_ina260.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_ina260.py b/adafruit_ina260.py index 9892bf4..7c48a26 100644 --- a/adafruit_ina260.py +++ b/adafruit_ina260.py @@ -19,6 +19,7 @@ """ # imports +import board try: from board import I2C @@ -173,7 +174,7 @@ class INA260: """ - def __init__(self, i2c_bus: I2C(), address: int = 0x40) -> None: + def __init__(self, i2c_bus: board.I2C(), address: int = 0x40) -> None: self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address) if self._manufacturer_id != self.TEXAS_INSTRUMENT_ID: From 2bb46f2e74cc8a31e35714750d1604d2730f218c Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 25 Aug 2022 12:09:14 -0400 Subject: [PATCH 5/8] Correct Missing Type Annotations --- adafruit_ina260.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/adafruit_ina260.py b/adafruit_ina260.py index 7c48a26..889cc8b 100644 --- a/adafruit_ina260.py +++ b/adafruit_ina260.py @@ -19,10 +19,9 @@ """ # imports -import board try: - from board import I2C + from board import I2C except ImportError: pass @@ -174,7 +173,7 @@ class INA260: """ - def __init__(self, i2c_bus: board.I2C(), address: int = 0x40) -> None: + 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: From d32574abe8095620c4ec312f75f2ab32ff57d6c6 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 25 Aug 2022 12:12:37 -0400 Subject: [PATCH 6/8] Correct Missing Type Annotations --- adafruit_ina260.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_ina260.py b/adafruit_ina260.py index 889cc8b..9892bf4 100644 --- a/adafruit_ina260.py +++ b/adafruit_ina260.py @@ -21,7 +21,7 @@ # imports try: - from board import I2C + from board import I2C except ImportError: pass From 940ff56e0b2bc962d9a45995c8a91bd527c72ffb Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 25 Aug 2022 12:34:36 -0400 Subject: [PATCH 7/8] Correct Missing Type Annotations --- adafruit_ina260.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_ina260.py b/adafruit_ina260.py index 9892bf4..bdbe2f7 100644 --- a/adafruit_ina260.py +++ b/adafruit_ina260.py @@ -21,6 +21,7 @@ # imports try: + import typing # pylint: disable=unused-import from board import I2C except ImportError: pass @@ -169,11 +170,11 @@ 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 address int: The I2C device address for the sensor. Default is ``0x40``. """ - def __init__(self, i2c_bus: I2C(), address: int = 0x40) -> None: + def __init__(self, i2c_bus: board.I2C, address: int = 0x40) -> None: self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address) if self._manufacturer_id != self.TEXAS_INSTRUMENT_ID: @@ -300,7 +301,7 @@ def voltage(self) -> float: return self._raw_voltage * 0.00125 @property - def power(self) -> float: + def power(self) -> int: """The power being delivered to the load in mW""" if self.mode == Mode.TRIGGERED: while self._conversion_ready_flag == 0: From 3c5ba581f477b611f0f2f695032015dab13bb7ba Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 25 Aug 2022 15:52:19 -0400 Subject: [PATCH 8/8] Correct Missing Type Annotations --- adafruit_ina260.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_ina260.py b/adafruit_ina260.py index bdbe2f7..ab38fd1 100644 --- a/adafruit_ina260.py +++ b/adafruit_ina260.py @@ -22,7 +22,7 @@ try: import typing # pylint: disable=unused-import - from board import I2C + from busio import I2C except ImportError: pass @@ -170,11 +170,11 @@ 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 int: 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: board.I2C, address: int = 0x40) -> None: + 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: