Skip to content
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

digital_inout.py: add exceptions when ipol register is absent #60

Merged
merged 5 commits into from
Oct 8, 2024
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:
tannewt marked this conversation as resolved.
Show resolved Hide resolved
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