use the enum module to represent states
[~helmut/onoff.git] / onoff / dbusutils.py
index 0477ed1..31b51cf 100644 (file)
@@ -103,15 +103,19 @@ class OnoffControl(dbus.service.Object):
         dbus.service.Object.__init__(self, busname, "%s/%s" % (self.path, name))
         self.device = device
         self.usecount = 0
-        device.notify.add(self.changestate)
+        device.notify.add(self._changestate_notifier)
+
+    def _changestate_notifier(self, state):
+        logger.debug("emitting state %s", state.name)
+        self.changestate(state.value)
 
     @dbus.service.signal(domain, signature="q")
     def changestate(self, state):
-        logger.debug("emitting state %d", state)
+        pass
 
     @dbus.service.method(domain, out_signature="q")
     def state(self):
-        return self.device.state
+        return self.device.state.value
 
     @dbus.service.method(domain, in_signature="q", out_signature="q")
     def activatetime(self, duration):
@@ -137,7 +141,7 @@ class OnoffControl(dbus.service.Object):
         self.usecount += 1
         if self.usecount <= 1:
             self.device.activate()
-        return self.device.state
+        return self.device.state.value
 
     def unuse(self):
         self.usecount -= 1