Skip to content
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
12 changes: 9 additions & 3 deletions adafruit_mcp230xx/digital_inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,19 @@ def invert_polarity(self) -> bool:
"""The polarity of the pin, either True for an Inverted or
False for an normal.
"""
if _get_bit(self._mcp.ipol, self._pin):
if hasattr(self._mcp, "ipol") and _get_bit(self._mcp.ipol, self._pin):
return True
return False

@invert_polarity.setter
def invert_polarity(self, val: bool) -> None:
if val:
self._mcp.ipol = _enable_bit(self._mcp.ipol, self._pin)
if hasattr(self._mcp, "ipol"):
self._mcp.ipol = _enable_bit(self._mcp.ipol, self._pin)
else:
raise ValueError("Inverted polarity is not supported.")
else:
self._mcp.ipol = _clear_bit(self._mcp.ipol, self._pin)
if hasattr(self._mcp, "ipol"):
self._mcp.ipol = _clear_bit(self._mcp.ipol, self._pin)
else:
return