Skip to content

Fix type annotations #10

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 3 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions adafruit_pcf8591/analog_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@

try:
import typing # pylint: disable=unused-import
from adafruit_pcf8591.pcf8591.PCF8591 import PCF8591
from typing_extensions import Literal
from adafruit_pcf8591.pcf8591 import PCF8591
except ImportError:
pass


class AnalogIn:
"""AnalogIn Mock Implementation for ADC Reads."""

def __init__(self, pcf: PCF8591, pin: int) -> None:
def __init__(self, pcf: PCF8591, pin: Literal[0, 1, 2, 3]) -> None:
"""AnalogIn

:param pcf: The PCF8591 object.
:param int pin: Required ADC channel pin.
:param int pin: Required ADC channel pin; must be 0-3 inclusive

"""
self._pcf = pcf
Expand Down
7 changes: 4 additions & 3 deletions adafruit_pcf8591/analog_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@
"""
try:
import typing # pylint: disable=unused-import
from adafruit_pcf8591.pcf8591.PCF8591 import PCF8591
from typing_extensions import Literal
from adafruit_pcf8591.pcf8591 import PCF8591
except ImportError:
pass


class AnalogOut:
"""AnalogIn Mock Implementation for ADC Reads."""

def __init__(self, pcf: PCF8591, dac_pin: int = 0) -> None:
def __init__(self, pcf: PCF8591, dac_pin: Literal[0] = 0) -> None:
"""AnalogIn

:param pcf: The pcf object.
:param int pin: Required pin must be adafruit_pcf8591.pcf8591.A0
:param int dac_pin: Required pin must be adafruit_pcf8591.pcf8591.A0

"""
self._pcf = pcf
Expand Down
2 changes: 1 addition & 1 deletion adafruit_pcf8591/pcf8591.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _half_read(self, channel: Literal[0, 1, 2, 3]) -> None:
with self.i2c_device as i2c:
i2c.write_then_readinto(self._buffer, self._buffer)

def read(self, channel: Literal[0, 1, 2, 3]) -> None:
def read(self, channel: Literal[0, 1, 2, 3]) -> int:
"""Read an analog value from one of the four ADC inputs

:param int channel: The single-ended ADC channel to read from, 0 thru 3
Expand Down