Skip to content

Commit e5b89be

Browse files
committed
Added remaining typehints
1 parent b62cfde commit e5b89be

File tree

9 files changed

+137
-131
lines changed

9 files changed

+137
-131
lines changed

adafruit_mcp230xx/digital_inout.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import digitalio
1616

1717
try:
18-
import typing # pylint: disable=unused-import
18+
from typing import Optional
1919
from adafruit_mcp230xx.mcp23xxx import MCP23XXX
2020
from digitalio import Pull, Direction
2121
except ImportError:
@@ -48,7 +48,7 @@ class DigitalInOut:
4848
configurations.
4949
"""
5050

51-
def __init__(self, pin_number: int, mcp230xx: MCP23XXX):
51+
def __init__(self, pin_number: int, mcp230xx: MCP23XXX) -> None:
5252
"""Specify the pin number of the MCP230xx (0...7 for MCP23008, or 0...15
5353
for MCP23017) and MCP23008 instance.
5454
"""
@@ -60,7 +60,7 @@ def __init__(self, pin_number: int, mcp230xx: MCP23XXX):
6060
# is unused by this class). Do not remove them, instead turn off pylint
6161
# in this case.
6262
# pylint: disable=unused-argument
63-
def switch_to_output(self, value: bool = False, **kwargs):
63+
def switch_to_output(self, value: bool = False, **kwargs) -> None:
6464
"""Switch the pin state to a digital output with the provided starting
6565
value (True/False for high or low, default is False/low).
6666
"""
@@ -69,7 +69,7 @@ def switch_to_output(self, value: bool = False, **kwargs):
6969

7070
def switch_to_input(
7171
self, pull: Pull = None, invert_polarity: bool = False, **kwargs
72-
):
72+
) -> None:
7373
"""Switch the pin state to a digital input with the provided starting
7474
pull-up resistor state (optional, no pull-up by default) and input polarity. Note that
7575
pull-down resistors are NOT supported!
@@ -81,22 +81,22 @@ def switch_to_input(
8181
# pylint: enable=unused-argument
8282

8383
@property
84-
def value(self):
84+
def value(self) -> bool:
8585
"""The value of the pin, either True for high or False for
8686
low. Note you must configure as an output or input appropriately
8787
before reading and writing this value.
8888
"""
8989
return _get_bit(self._mcp.gpio, self._pin)
9090

9191
@value.setter
92-
def value(self, val: bool):
92+
def value(self, val: bool) -> None:
9393
if val:
9494
self._mcp.gpio = _enable_bit(self._mcp.gpio, self._pin)
9595
else:
9696
self._mcp.gpio = _clear_bit(self._mcp.gpio, self._pin)
9797

9898
@property
99-
def direction(self):
99+
def direction(self) -> bool:
100100
"""The direction of the pin, either True for an input or
101101
False for an output.
102102
"""
@@ -105,7 +105,7 @@ def direction(self):
105105
return digitalio.Direction.OUTPUT
106106

107107
@direction.setter
108-
def direction(self, val: Direction):
108+
def direction(self, val: Direction) -> None:
109109
if val == digitalio.Direction.INPUT:
110110
self._mcp.iodir = _enable_bit(self._mcp.iodir, self._pin)
111111
elif val == digitalio.Direction.OUTPUT:
@@ -114,7 +114,7 @@ def direction(self, val: Direction):
114114
raise ValueError("Expected INPUT or OUTPUT direction!")
115115

116116
@property
117-
def pull(self):
117+
def pull(self) -> Optional[digitalio.Pull]:
118118
"""Enable or disable internal pull-up resistors for this pin. A
119119
value of digitalio.Pull.UP will enable a pull-up resistor, and None will
120120
disable it. Pull-down resistors are NOT supported!
@@ -128,7 +128,7 @@ def pull(self):
128128
return None
129129

130130
@pull.setter
131-
def pull(self, val: Pull):
131+
def pull(self, val: Pull) -> None:
132132
try:
133133
if val is None:
134134
self._mcp.gppu = _clear_bit(self._mcp.gppu, self._pin)
@@ -143,7 +143,7 @@ def pull(self, val: Pull):
143143
raise ValueError("Pull-up/pull-down resistors not supported.") from error
144144

145145
@property
146-
def invert_polarity(self):
146+
def invert_polarity(self) -> bool:
147147
"""The polarity of the pin, either True for an Inverted or
148148
False for an normal.
149149
"""
@@ -152,7 +152,7 @@ def invert_polarity(self):
152152
return False
153153

154154
@invert_polarity.setter
155-
def invert_polarity(self, val: bool):
155+
def invert_polarity(self, val: bool) -> None:
156156
if val:
157157
self._mcp.ipol = _enable_bit(self._mcp.ipol, self._pin)
158158
else:

adafruit_mcp230xx/mcp23008.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class MCP23008(MCP230XX):
4343
at the specified I2C address.
4444
"""
4545

46-
def __init__(self, i2c: I2C, address: int = _MCP23008_ADDRESS, reset: bool = True):
46+
def __init__(
47+
self, i2c: I2C, address: int = _MCP23008_ADDRESS, reset: bool = True
48+
) -> None:
4749
super().__init__(i2c, address)
4850

4951
if reset:
@@ -53,38 +55,38 @@ def __init__(self, i2c: I2C, address: int = _MCP23008_ADDRESS, reset: bool = Tru
5355
self._write_u8(_MCP23008_IPOL, 0x00)
5456

5557
@property
56-
def gpio(self):
58+
def gpio(self) -> int:
5759
"""The raw GPIO output register. Each bit represents the
5860
output value of the associated pin (0 = low, 1 = high), assuming that
5961
pin has been configured as an output previously.
6062
"""
6163
return self._read_u8(_MCP23008_GPIO)
6264

6365
@gpio.setter
64-
def gpio(self, val: int):
66+
def gpio(self, val: int) -> None:
6567
self._write_u8(_MCP23008_GPIO, val)
6668

6769
@property
68-
def iodir(self):
70+
def iodir(self) -> int:
6971
"""The raw IODIR direction register. Each bit represents
7072
direction of a pin, either 1 for an input or 0 for an output mode.
7173
"""
7274
return self._read_u8(_MCP23008_IODIR)
7375

7476
@iodir.setter
75-
def iodir(self, val: int):
77+
def iodir(self, val: int) -> None:
7678
self._write_u8(_MCP23008_IODIR, val)
7779

7880
@property
79-
def gppu(self):
81+
def gppu(self) -> int:
8082
"""The raw GPPU pull-up register. Each bit represents
8183
if a pull-up is enabled on the specified pin (1 = pull-up enabled,
8284
0 = pull-up disabled). Note pull-down resistors are NOT supported!
8385
"""
8486
return self._read_u8(_MCP23008_GPPU)
8587

8688
@gppu.setter
87-
def gppu(self, val: int):
89+
def gppu(self, val: int) -> None:
8890
self._write_u8(_MCP23008_GPPU, val)
8991

9092
def get_pin(self, pin: int) -> DigitalInOut:

adafruit_mcp230xx/mcp23016.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class MCP23016(MCP230XX):
5151
at the specified I2C address.
5252
"""
5353

54-
def __init__(self, i2c: I2C, address: int = _MCP23016_ADDRESS, reset: bool = True):
54+
def __init__(
55+
self, i2c: I2C, address: int = _MCP23016_ADDRESS, reset: bool = True
56+
) -> None:
5557
super().__init__(i2c, address)
5658

5759
if reset:
@@ -60,72 +62,72 @@ def __init__(self, i2c: I2C, address: int = _MCP23016_ADDRESS, reset: bool = Tru
6062
self._write_u16le(_MCP23016_IPOL0, 0x0000)
6163

6264
@property
63-
def gpio(self):
65+
def gpio(self) -> int:
6466
"""The raw GPIO output register. Each bit represents the
6567
output value of the associated pin (0 = low, 1 = high), assuming that
6668
pin has been configured as an output previously.
6769
"""
6870
return self._read_u16le(_MCP23016_GPIO0)
6971

7072
@gpio.setter
71-
def gpio(self, val: int):
73+
def gpio(self, val: int) -> None:
7274
self._write_u16le(_MCP23016_GPIO0, val)
7375

7476
@property
75-
def gpioa(self):
77+
def gpioa(self) -> int:
7678
"""The raw GPIO 0 output register. Each bit represents the
7779
output value of the associated pin (0 = low, 1 = high), assuming that
7880
pin has been configured as an output previously.
7981
"""
8082
return self._read_u8(_MCP23016_GPIO0)
8183

8284
@gpioa.setter
83-
def gpioa(self, val: int):
85+
def gpioa(self, val: int) -> None:
8486
self._write_u8(_MCP23016_GPIO0, val)
8587

8688
@property
87-
def gpiob(self):
89+
def gpiob(self) -> int:
8890
"""The raw GPIO 1 output register. Each bit represents the
8991
output value of the associated pin (0 = low, 1 = high), assuming that
9092
pin has been configured as an output previously.
9193
"""
9294
return self._read_u8(_MCP23016_GPIO1)
9395

9496
@gpiob.setter
95-
def gpiob(self, val: int):
97+
def gpiob(self, val: int) -> None:
9698
self._write_u8(_MCP23016_GPIO1, val)
9799

98100
@property
99-
def iodir(self):
101+
def iodir(self) -> int:
100102
"""The raw IODIR direction register. Each bit represents
101103
direction of a pin, either 1 for an input or 0 for an output mode.
102104
"""
103105
return self._read_u16le(_MCP23016_IODIR0)
104106

105107
@iodir.setter
106-
def iodir(self, val: int):
108+
def iodir(self, val: int) -> None:
107109
self._write_u16le(_MCP23016_IODIR0, val)
108110

109111
@property
110-
def iodira(self):
112+
def iodira(self) -> int:
111113
"""The raw IODIR0 direction register. Each bit represents
112114
direction of a pin, either 1 for an input or 0 for an output mode.
113115
"""
114116
return self._read_u8(_MCP23016_IODIR0)
115117

116118
@iodira.setter
117-
def iodira(self, val: int):
119+
def iodira(self, val: int) -> None:
118120
self._write_u8(_MCP23016_IODIR0, val)
119121

120122
@property
121-
def iodirb(self):
123+
def iodirb(self) -> int:
122124
"""The raw IODIR0 direction register. Each bit represents
123125
direction of a pin, either 1 for an input or 0 for an output mode.
124126
"""
125127
return self._read_u8(_MCP23016_IODIR1)
126128

127129
@iodirb.setter
128-
def iodirb(self, val: int):
130+
def iodirb(self, val: int) -> None:
129131
self._write_u8(_MCP23016_IODIR1, val)
130132

131133
def get_pin(self, pin: int) -> DigitalInOut:
@@ -136,10 +138,10 @@ def get_pin(self, pin: int) -> DigitalInOut:
136138
raise ValueError("Pin number must be 0-15.")
137139
return DigitalInOut(pin, self)
138140

139-
def clear_inta(self):
141+
def clear_inta(self) -> None:
140142
"""Clears port 0 interrupts."""
141143
self._read_u8(_MCP23016_INTCAP0)
142144

143-
def clear_intb(self):
145+
def clear_intb(self) -> None:
144146
"""Clears port 1 interrupts."""
145147
self._read_u8(_MCP23016_INTCAP1)

0 commit comments

Comments
 (0)