diff --git a/adafruit_mcp230xx/digital_inout.py b/adafruit_mcp230xx/digital_inout.py index e3b57e2..17e8dcd 100644 --- a/adafruit_mcp230xx/digital_inout.py +++ b/adafruit_mcp230xx/digital_inout.py @@ -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