Skip to content

Commit 06dd5c6

Browse files
authored
Merge pull request #60 from regicidalplutophage/patch-1
digital_inout.py: add exceptions when ipol register is absent
2 parents c723751 + 84a1f25 commit 06dd5c6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

adafruit_mcp230xx/digital_inout.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,19 @@ def invert_polarity(self) -> bool:
148148
"""The polarity of the pin, either True for an Inverted or
149149
False for an normal.
150150
"""
151-
if _get_bit(self._mcp.ipol, self._pin):
151+
if hasattr(self._mcp, "ipol") and _get_bit(self._mcp.ipol, self._pin):
152152
return True
153153
return False
154154

155155
@invert_polarity.setter
156156
def invert_polarity(self, val: bool) -> None:
157157
if val:
158-
self._mcp.ipol = _enable_bit(self._mcp.ipol, self._pin)
158+
if hasattr(self._mcp, "ipol"):
159+
self._mcp.ipol = _enable_bit(self._mcp.ipol, self._pin)
160+
else:
161+
raise ValueError("Inverted polarity is not supported.")
159162
else:
160-
self._mcp.ipol = _clear_bit(self._mcp.ipol, self._pin)
163+
if hasattr(self._mcp, "ipol"):
164+
self._mcp.ipol = _clear_bit(self._mcp.ipol, self._pin)
165+
else:
166+
return

0 commit comments

Comments
 (0)