diff mbox series

[libgpiod,2/2] bindings: python: support casting line.Value to bool

Message ID 20240522004643.96863-3-warthog618@gmail.com
State New
Headers show
Series support casting line.Value to bool | expand

Commit Message

Kent Gibson May 22, 2024, 12:46 a.m. UTC
Python types default to being truthy when cast to bool, so casting
line.Value to bool always returns True.

Add a line.Value.__bool__() operator to map the line value to bool as
one would intuitively expect, so ACTIVE is True and INACTIVE is False.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
---
 bindings/python/gpiod/line.py | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/bindings/python/gpiod/line.py b/bindings/python/gpiod/line.py
index 1cc512f..d088fb4 100644
--- a/bindings/python/gpiod/line.py
+++ b/bindings/python/gpiod/line.py
@@ -14,6 +14,9 @@  class Value(Enum):
     INACTIVE = _ext.VALUE_INACTIVE
     ACTIVE = _ext.VALUE_ACTIVE
 
+    def __bool__(self):
+        return self == self.ACTIVE
+
 
 class Direction(Enum):
     """Direction settings."""