-
Notifications
You must be signed in to change notification settings - Fork 15
Fix a few type hints #34
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,14 +29,15 @@ | |
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 | ||
|
||
_CONVERT = b"\x44" | ||
_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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declares RESOLUTION as a tuple where each value is in the set (9, 10, 11, 12). This allows IDEs and type checkers to more strictly validate the values being accessed inside this tuple variable. |
||
# Maximum conversion delay in seconds, from DS18B20 datasheet. | ||
_CONVERSION_DELAY = {9: 0.09375, 10: 0.1875, 11: 0.375, 12: 0.750} | ||
|
||
|
@@ -74,7 +75,7 @@ class DS18X20: | |
|
||
""" | ||
|
||
def __init__(self, bus: OneWireBus, address: int) -> None: | ||
def __init__(self, bus: OneWireBus, address: OneWireAddress) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main fix here - it's not an |
||
if address.family_code in (0x10, 0x28): | ||
self._address = address | ||
self._device = OneWireDevice(bus, address) | ||
|
@@ -84,7 +85,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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor tweak, this returns a float for the temperature. |
||
"""The temperature in degrees Celsius.""" | ||
self._convert_temp() | ||
return self._read_temp() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New import only for type hinting, so it is inside the try block.