tristate: implement __nonzero__() method
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 2 Jun 2014 07:14:52 +0000 (10:14 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 5 Jun 2014 13:15:53 +0000 (16:15 +0300)
Returns False if tristate is 'off', otherwise True ('on' or 'auto').

Change-Id: I6ade27fc85c6d05ed69dc694495b70725070d9c5
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/tristate.py

index 9361060..0a800ec 100644 (file)
@@ -66,6 +66,17 @@ class Tristate(object):
         else:
             return 'off'
 
+    def __nonzero__(self):
+        """
+        >>> Tristate('on').__nonzero__()
+        True
+        >>> Tristate('auto').__nonzero__()
+        True
+        >>> Tristate('off').__nonzero__()
+        False
+        """
+        return self._state is not self.OFF
+
     @property
     def state(self):
         """Get current state"""