From ea30615099c0727b718c0eea840f7d5d60f7d222 Mon Sep 17 00:00:00 2001 From: Edwin Lee Date: Mon, 7 Apr 2025 09:00:29 -0500 Subject: [PATCH 1/2] Fix three type hints --- adafruit_ds18x20.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_ds18x20.py b/adafruit_ds18x20.py index 35f01f6..7506a58 100644 --- a/adafruit_ds18x20.py +++ b/adafruit_ds18x20.py @@ -22,7 +22,7 @@ import time from micropython import const -from adafruit_onewire.device import OneWireDevice +from adafruit_onewire.device import OneWireAddress, OneWireDevice try: import typing # pylint: disable=unused-import @@ -36,7 +36,7 @@ _RD_SCRATCH = b"\xBE" _WR_SCRATCH = b"\x4E" _CONVERSION_TIMEOUT = const(1) -RESOLUTION = (9, 10, 11, 12) +RESOLUTION: tuple[Literal[9, 10, 11, 12], ...] = (9, 10, 11, 12) # Maximum conversion delay in seconds, from DS18B20 datasheet. _CONVERSION_DELAY = {9: 0.09375, 10: 0.1875, 11: 0.375, 12: 0.750} @@ -74,7 +74,7 @@ class DS18X20: """ - def __init__(self, bus: OneWireBus, address: int) -> None: + def __init__(self, bus: OneWireBus, address: OneWireAddress) -> None: if address.family_code in (0x10, 0x28): self._address = address self._device = OneWireDevice(bus, address) @@ -84,7 +84,7 @@ def __init__(self, bus: OneWireBus, address: int) -> None: raise ValueError("Incorrect family code in device address.") @property - def temperature(self): + def temperature(self) -> float: """The temperature in degrees Celsius.""" self._convert_temp() return self._read_temp() From 132c666b51bfe967afeb565c6cb2edf40df2c8de Mon Sep 17 00:00:00 2001 From: Edwin Lee Date: Tue, 8 Apr 2025 09:32:20 -0500 Subject: [PATCH 2/2] Move import into try block --- adafruit_ds18x20.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_ds18x20.py b/adafruit_ds18x20.py index 7506a58..292ba03 100644 --- a/adafruit_ds18x20.py +++ b/adafruit_ds18x20.py @@ -22,13 +22,14 @@ import time from micropython import const -from adafruit_onewire.device import OneWireAddress, OneWireDevice +from adafruit_onewire.device import OneWireDevice try: import typing # pylint: disable=unused-import from typing_extensions import Literal from circuitpython_typing import WriteableBuffer from adafruit_onewire.bus import OneWireBus # pylint: disable=ungrouped-imports + from adafruit_onewire.device import OneWireAddress except ImportError: pass