use the enum module to represent states
[~helmut/onoff.git] / onoff / gpio.py
index bea9708..954c6ff 100644 (file)
@@ -1,6 +1,6 @@
 import os.path
 
-from .common import OnoffDevice, ST_ACTIVE
+from .common import OnoffDevice, OnoffState
 
 def _write_file_value(path, content):
     with open(path, "w") as f:
@@ -17,7 +17,7 @@ class OnoffGPIO(OnoffDevice):
         @param active_low: whether the GPIO should be inverted
         """
         OnoffDevice.__init__(self)
-        self.current_state = 0
+        self.current_state = OnoffState.inactive
         basedir = "/sys/class/gpio"
         self.gpiodir = "%s/gpio%d" % (basedir, gpionumber)
         if not os.path.isdir(self.gpiodir):
@@ -28,7 +28,7 @@ class OnoffGPIO(OnoffDevice):
     def _set_state(self, state):
         self.current_state = state
         _write_file_value("%s/value" % self.gpiodir,
-                         "1" if self.current_state == ST_ACTIVE else "0")
+                          "1" if state == OnoffState.active else "0")
         self.changestate(self.current_state)
 
     @property
@@ -36,7 +36,7 @@ class OnoffGPIO(OnoffDevice):
         return self.current_state
 
     def activate(self):
-        self._set_state(ST_ACTIVE)
+        self._set_state(OnoffState.active)
 
     def deactivate(self):
-        self._set_state(0)
+        self._set_state(OnoffState.inactive)