Skip to content

Add Missing Type Annotations #12

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

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions adafruit_ds3502.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
from adafruit_register.i2c_bit import RWBit
import adafruit_bus_device.i2c_device as i2cdevice

try:
import typing # pylint: disable=unused-import
from busio import I2C
except ImportError:
pass

_REG_WIPER = const(0x00) # Wiper value register (R/W)
_REG_CONTROL = const(0x02) # Configuration Register (R/W)

Expand All @@ -52,7 +58,7 @@ class DS3502:
:param address: The I2C device address for the sensor. Default is ``0x40``.
"""

def __init__(self, i2c_bus, address=0x28):
def __init__(self, i2c_bus: I2C, address: int = 0x28) -> None:
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)

# set to mode 1 on init to not write to the IVR every time you set
Expand All @@ -62,20 +68,20 @@ def __init__(self, i2c_bus, address=0x28):
_write_only_to_wiper = RWBit(_REG_CONTROL, 7)

@property
def wiper(self):
def wiper(self) -> int:
"""The value of the potentionmeter's wiper.

:param wiper_value: The value from 0-127 to set the wiper to.
"""
return self._wiper

@wiper.setter
def wiper(self, value):
def wiper(self, value: int) -> None:
if value < 0 or value > 127:
raise ValueError("wiper must be from 0-127")
self._wiper = value

def set_default(self, default):
def set_default(self, default: int) -> None:
"""Sets the wiper's default value and current value to the given value

:param new_default: The value from 0-127 to set as the wiper's default.
Expand Down