From 0058a136b42e08cd5fea7228952c979e4d2db813 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Sat, 20 Aug 2022 13:56:15 -0400 Subject: [PATCH 1/6] Correct Missing Type Annotations --- adafruit_sht4x.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/adafruit_sht4x.py b/adafruit_sht4x.py index 958835e..d5f5c96 100644 --- a/adafruit_sht4x.py +++ b/adafruit_sht4x.py @@ -30,9 +30,16 @@ import time import struct + +import board from adafruit_bus_device import i2c_device from micropython import const +try: + from typing import Tuple +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SHT4x.git" @@ -46,7 +53,7 @@ class CV: """struct helper""" @classmethod - def add_values(cls, value_tuples): + def add_values(cls, value_tuples) -> None: """Add CV values to the class""" cls.string = {} cls.delay = {} @@ -58,7 +65,7 @@ def add_values(cls, value_tuples): cls.delay[value] = delay @classmethod - def is_valid(cls, value): + def is_valid(cls, value) -> bool: """Validate that a given value is a member""" return value in cls.string @@ -126,14 +133,16 @@ class SHT4x: """ - def __init__(self, i2c_bus, address=_SHT4X_DEFAULT_ADDR): + def __init__( + self, i2c_bus: board.I2C(), address: int = _SHT4X_DEFAULT_ADDR + ) -> None: self.i2c_device = i2c_device.I2CDevice(i2c_bus, address) self._buffer = bytearray(6) self.reset() self._mode = Mode.NOHEAT_HIGHPRECISION # pylint: disable=no-member @property - def serial_number(self): + def serial_number(self) -> int: """The unique 32-bit serial number""" self._buffer[0] = _SHT4X_READSERIAL with self.i2c_device as i2c: @@ -153,7 +162,7 @@ def serial_number(self): serial = (ser1[0] << 24) + (ser1[1] << 16) + (ser2[0] << 8) + ser2[1] return serial - def reset(self): + def reset(self) -> None: """Perform a soft reset of the sensor, resetting all settings to their power-on defaults""" self._buffer[0] = _SHT4X_SOFTRESET with self.i2c_device as i2c: @@ -161,29 +170,29 @@ def reset(self): time.sleep(0.001) @property - def mode(self): + def mode(self) -> int: """The current sensor reading mode (heater and precision)""" return self._mode @mode.setter - def mode(self, new_mode): + def mode(self, new_mode: int) -> None: if not Mode.is_valid(new_mode): raise AttributeError("mode must be a Mode") self._mode = new_mode @property - def relative_humidity(self): + def relative_humidity(self) -> float: """The current relative humidity in % rH. This is a value from 0-100%.""" return self.measurements[1] @property - def temperature(self): + def temperature(self) -> float: """The current temperature in degrees Celsius""" return self.measurements[0] @property - def measurements(self): + def measurements(self) -> Tuple[float, float]: """both `temperature` and `relative_humidity`, read simultaneously""" temperature = None @@ -226,7 +235,7 @@ def measurements(self): # Test data [0xBE, 0xEF] should yield 0x92 @staticmethod - def _crc8(buffer): + def _crc8(buffer) -> int: """verify the crc8 checksum""" crc = 0xFF for byte in buffer: From 7dcde6c36dc521d2e623ed7eadee6b692ee3abdc Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Sat, 20 Aug 2022 14:01:01 -0400 Subject: [PATCH 2/6] Correct Missing Type Annotations --- adafruit_sht4x.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_sht4x.py b/adafruit_sht4x.py index d5f5c96..97974a1 100644 --- a/adafruit_sht4x.py +++ b/adafruit_sht4x.py @@ -37,6 +37,7 @@ try: from typing import Tuple + from busio import I2C except ImportError: pass @@ -134,7 +135,7 @@ class SHT4x: """ def __init__( - self, i2c_bus: board.I2C(), address: int = _SHT4X_DEFAULT_ADDR + self, i2c_bus: I2C, address: int = _SHT4X_DEFAULT_ADDR ) -> None: self.i2c_device = i2c_device.I2CDevice(i2c_bus, address) self._buffer = bytearray(6) From 4d73b6b39546667514284f9fe9119e7f029955d3 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Sat, 20 Aug 2022 14:07:02 -0400 Subject: [PATCH 3/6] Correct Missing Type Annotations --- adafruit_sht4x.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/adafruit_sht4x.py b/adafruit_sht4x.py index 97974a1..5a51bd6 100644 --- a/adafruit_sht4x.py +++ b/adafruit_sht4x.py @@ -30,8 +30,6 @@ import time import struct - -import board from adafruit_bus_device import i2c_device from micropython import const @@ -134,9 +132,7 @@ class SHT4x: """ - def __init__( - self, i2c_bus: I2C, address: int = _SHT4X_DEFAULT_ADDR - ) -> None: + def __init__(self, i2c_bus: I2C, address: int = _SHT4X_DEFAULT_ADDR) -> None: self.i2c_device = i2c_device.I2CDevice(i2c_bus, address) self._buffer = bytearray(6) self.reset() From 0b832a7fb2348b9cf9b29bb1c8134c4c6c217141 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Mon, 22 Aug 2022 19:55:27 -0400 Subject: [PATCH 4/6] Correct Missing Type Annotations --- adafruit_sht4x.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_sht4x.py b/adafruit_sht4x.py index 5a51bd6..81067f1 100644 --- a/adafruit_sht4x.py +++ b/adafruit_sht4x.py @@ -52,7 +52,7 @@ class CV: """struct helper""" @classmethod - def add_values(cls, value_tuples) -> None: + def add_values(cls, value_tuples: Tuple[str, int, Union[float, str], Optional[float]]) -> None: """Add CV values to the class""" cls.string = {} cls.delay = {} @@ -64,7 +64,7 @@ def add_values(cls, value_tuples) -> None: cls.delay[value] = delay @classmethod - def is_valid(cls, value) -> bool: + def is_valid(cls, value: str) -> bool: """Validate that a given value is a member""" return value in cls.string From 3319bc1d404ee84d93c1f510e334abb49df9915d Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Mon, 22 Aug 2022 20:01:22 -0400 Subject: [PATCH 5/6] Correct Missing Type Annotations --- adafruit_sht4x.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_sht4x.py b/adafruit_sht4x.py index 81067f1..39c4c22 100644 --- a/adafruit_sht4x.py +++ b/adafruit_sht4x.py @@ -34,7 +34,7 @@ from micropython import const try: - from typing import Tuple + from typing import Tuple, Union, Optional from busio import I2C except ImportError: pass @@ -52,7 +52,9 @@ class CV: """struct helper""" @classmethod - def add_values(cls, value_tuples: Tuple[str, int, Union[float, str], Optional[float]]) -> None: + def add_values( + cls, value_tuples: Tuple[str, int, Union[float, str], Optional[float]] + ) -> None: """Add CV values to the class""" cls.string = {} cls.delay = {} From b4f5b86f518e42645bd19699e5dcebcd2084ba1b Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Tue, 23 Aug 2022 09:31:34 -0400 Subject: [PATCH 6/6] Correct Missing Type Annotations --- adafruit_sht4x.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/adafruit_sht4x.py b/adafruit_sht4x.py index 39c4c22..3d971ae 100644 --- a/adafruit_sht4x.py +++ b/adafruit_sht4x.py @@ -34,7 +34,7 @@ from micropython import const try: - from typing import Tuple, Union, Optional + from typing import Tuple from busio import I2C except ImportError: pass @@ -52,9 +52,7 @@ class CV: """struct helper""" @classmethod - def add_values( - cls, value_tuples: Tuple[str, int, Union[float, str], Optional[float]] - ) -> None: + def add_values(cls, value_tuples: Tuple[str, int, str, float]) -> None: """Add CV values to the class""" cls.string = {} cls.delay = {} @@ -66,7 +64,7 @@ def add_values( cls.delay[value] = delay @classmethod - def is_valid(cls, value: str) -> bool: + def is_valid(cls, value: int) -> bool: """Validate that a given value is a member""" return value in cls.string