From b0f0ba1f8fe96077d4d38ea4c4569b9e969cc143 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Sun, 21 Aug 2022 19:45:32 -0400 Subject: [PATCH 1/9] Correct Missing Type Annotations --- adafruit_tlv493d.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/adafruit_tlv493d.py b/adafruit_tlv493d.py index 68a286b..20ca677 100644 --- a/adafruit_tlv493d.py +++ b/adafruit_tlv493d.py @@ -32,6 +32,12 @@ import adafruit_bus_device.i2c_device as i2cdevice from micropython import const +try: + from typing import Tuple + from busio import I2C +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_TLV493D.git" @@ -102,7 +108,9 @@ class TLV493D: "RES3": (3, 0x1F, 0), } - def __init__(self, i2c_bus, address=_TLV493D_DEFAULT_ADDRESS, addr_reg=0): + def __init__( + self, i2c_bus: I2C, address: int = _TLV493D_DEFAULT_ADDRESS, addr_reg: int = 0 + ) -> None: self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address) self.read_buffer = bytearray(10) self.write_buffer = bytearray(4) @@ -119,28 +127,28 @@ def __init__(self, i2c_bus, address=_TLV493D_DEFAULT_ADDRESS, addr_reg=0): self._set_write_key("LOWPOWER", 1) self._write_i2c() - def _read_i2c(self): + def _read_i2c(self) -> None: with self.i2c_device as i2c: i2c.readinto(self.read_buffer) # self.print_bytes(self.read_buffer) - def _write_i2c(self): + def _write_i2c(self) -> None: with self.i2c_device as i2c: i2c.write(self.write_buffer) - def _setup_write_buffer(self): + def _setup_write_buffer(self) -> None: self._read_i2c() for key in ["RES1", "RES2", "RES3"]: write_value = self._get_read_key(key) self._set_write_key(key, write_value) - def _get_read_key(self, key): + def _get_read_key(self, key: int) -> int: read_byte_num, read_mask, read_shift = self.read_masks[key] raw_read_value = self.read_buffer[read_byte_num] write_value = (raw_read_value & read_mask) >> read_shift return write_value - def _set_write_key(self, key, value): + def _set_write_key(self, key: int, value: int) -> None: write_byte_num, write_mask, write_shift = self.write_masks[key] current_write_byte = self.write_buffer[write_byte_num] current_write_byte &= ~write_mask @@ -148,7 +156,7 @@ def _set_write_key(self, key, value): self.write_buffer[write_byte_num] = current_write_byte @property - def magnetic(self): + def magnetic(self) -> Tuple[float, float, float]: """The processed magnetometer sensor values. A 3-tuple of X, Y, Z axis values in microteslas that are signed floats. """ @@ -166,7 +174,9 @@ def magnetic(self): self._unpack_and_scale(z_top, z_bot), ) - def _unpack_and_scale(self, top, bottom): # pylint: disable=no-self-use + def _unpack_and_scale( + self, top: int, bottom: int + ) -> float: # pylint: disable=no-self-use binval = struct.unpack_from(">h", bytearray([top, bottom]))[0] binval = binval >> 4 return binval * 0.098 From bb29060d4e56c074703d66c9b29cbddee910c6ae Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Sun, 21 Aug 2022 19:50:18 -0400 Subject: [PATCH 2/9] Correct Missing Type Annotations --- adafruit_tlv493d.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adafruit_tlv493d.py b/adafruit_tlv493d.py index 20ca677..1ee1a73 100644 --- a/adafruit_tlv493d.py +++ b/adafruit_tlv493d.py @@ -174,9 +174,7 @@ def magnetic(self) -> Tuple[float, float, float]: self._unpack_and_scale(z_top, z_bot), ) - def _unpack_and_scale( - self, top: int, bottom: int - ) -> float: # pylint: disable=no-self-use + def _unpack_and_scale(self, top: int, bottom: int) -> float: # pylint: disable=no-self-use binval = struct.unpack_from(">h", bytearray([top, bottom]))[0] binval = binval >> 4 return binval * 0.098 From 5ac64b0ea87abb548b251a22ea122d6136b2b0e3 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Sun, 21 Aug 2022 20:46:19 -0400 Subject: [PATCH 3/9] Correct Missing Type Annotations --- adafruit_tlv493d.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_tlv493d.py b/adafruit_tlv493d.py index 1ee1a73..4afa76e 100644 --- a/adafruit_tlv493d.py +++ b/adafruit_tlv493d.py @@ -174,7 +174,9 @@ def magnetic(self) -> Tuple[float, float, float]: self._unpack_and_scale(z_top, z_bot), ) - def _unpack_and_scale(self, top: int, bottom: int) -> float: # pylint: disable=no-self-use + # pylint: disable=no-self-use + def _unpack_and_scale(self, top: int, bottom: int) -> float: + # pylint: enable=no-self-use binval = struct.unpack_from(">h", bytearray([top, bottom]))[0] binval = binval >> 4 return binval * 0.098 From 807e866b738406251497ea66827de858ee2d2c1e Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Mon, 22 Aug 2022 10:13:47 -0400 Subject: [PATCH 4/9] Correct Missing Type Annotations --- .pylintrc | 2 +- adafruit_tlv493d.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index f772971..bdec525 100644 --- a/.pylintrc +++ b/.pylintrc @@ -26,7 +26,7 @@ jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins= +load-plugins=pylint.extensions.no_self_use # Pickle collected data for later comparisons. persistent=yes diff --git a/adafruit_tlv493d.py b/adafruit_tlv493d.py index 4afa76e..de0fb32 100644 --- a/adafruit_tlv493d.py +++ b/adafruit_tlv493d.py @@ -175,8 +175,10 @@ def magnetic(self) -> Tuple[float, float, float]: ) # pylint: disable=no-self-use - def _unpack_and_scale(self, top: int, bottom: int) -> float: - # pylint: enable=no-self-use + def _unpack_and_scale( + self, top: int, bottom: int + ) -> float: binval = struct.unpack_from(">h", bytearray([top, bottom]))[0] binval = binval >> 4 return binval * 0.098 + # pylint: enable=no-self-use From 3d5bc9a2e2a3eaf2557b1970de73d8ceda34133f Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Mon, 22 Aug 2022 10:17:41 -0400 Subject: [PATCH 5/9] Correct Missing Type Annotations --- adafruit_tlv493d.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/adafruit_tlv493d.py b/adafruit_tlv493d.py index de0fb32..9fd9666 100644 --- a/adafruit_tlv493d.py +++ b/adafruit_tlv493d.py @@ -175,10 +175,9 @@ def magnetic(self) -> Tuple[float, float, float]: ) # pylint: disable=no-self-use - def _unpack_and_scale( - self, top: int, bottom: int - ) -> float: + def _unpack_and_scale(self, top: int, bottom: int) -> float: binval = struct.unpack_from(">h", bytearray([top, bottom]))[0] binval = binval >> 4 return binval * 0.098 + # pylint: enable=no-self-use From 155ea219bf2a207f83959998365a557537997208 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Mon, 22 Aug 2022 10:52:26 -0400 Subject: [PATCH 6/9] Correct Missing Type Annotations --- adafruit_tlv493d.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/adafruit_tlv493d.py b/adafruit_tlv493d.py index 9fd9666..a2969a6 100644 --- a/adafruit_tlv493d.py +++ b/adafruit_tlv493d.py @@ -174,10 +174,9 @@ def magnetic(self) -> Tuple[float, float, float]: self._unpack_and_scale(z_top, z_bot), ) - # pylint: disable=no-self-use - def _unpack_and_scale(self, top: int, bottom: int) -> float: + def _unpack_and_scale( # pylint: disable=no-self-use + self, top: int, bottom: int + ) -> float: binval = struct.unpack_from(">h", bytearray([top, bottom]))[0] binval = binval >> 4 return binval * 0.098 - - # pylint: enable=no-self-use From 56780ff2d24d5604b5b2c97b17f7ae72f3ffe602 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Mon, 22 Aug 2022 10:55:39 -0400 Subject: [PATCH 7/9] Correct Missing Type Annotations --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index bdec525..f772971 100644 --- a/.pylintrc +++ b/.pylintrc @@ -26,7 +26,7 @@ jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins=pylint.extensions.no_self_use +load-plugins= # Pickle collected data for later comparisons. persistent=yes From 41071bbe946331fa43d0bd9ef408dbd60b743d0c Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Mon, 22 Aug 2022 12:51:18 -0400 Subject: [PATCH 8/9] change _unpack_and_scale to @staticmethod --- adafruit_tlv493d.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/adafruit_tlv493d.py b/adafruit_tlv493d.py index a2969a6..0693379 100644 --- a/adafruit_tlv493d.py +++ b/adafruit_tlv493d.py @@ -174,9 +174,8 @@ def magnetic(self) -> Tuple[float, float, float]: self._unpack_and_scale(z_top, z_bot), ) - def _unpack_and_scale( # pylint: disable=no-self-use - self, top: int, bottom: int - ) -> float: + @staticmethod + def _unpack_and_scale(top: int, bottom: int) -> float: binval = struct.unpack_from(">h", bytearray([top, bottom]))[0] binval = binval >> 4 return binval * 0.098 From 7b784f6164a87936fa3b80171292a4afe0d40b22 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Mon, 22 Aug 2022 20:12:17 -0400 Subject: [PATCH 9/9] change _unpack_and_scale to @staticmethod --- adafruit_tlv493d.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_tlv493d.py b/adafruit_tlv493d.py index 0693379..3f0c954 100644 --- a/adafruit_tlv493d.py +++ b/adafruit_tlv493d.py @@ -142,13 +142,13 @@ def _setup_write_buffer(self) -> None: write_value = self._get_read_key(key) self._set_write_key(key, write_value) - def _get_read_key(self, key: int) -> int: + def _get_read_key(self, key: str) -> int: read_byte_num, read_mask, read_shift = self.read_masks[key] raw_read_value = self.read_buffer[read_byte_num] write_value = (raw_read_value & read_mask) >> read_shift return write_value - def _set_write_key(self, key: int, value: int) -> None: + def _set_write_key(self, key: str, value: int) -> None: write_byte_num, write_mask, write_shift = self.write_masks[key] current_write_byte = self.write_buffer[write_byte_num] current_write_byte &= ~write_mask