silence sphinx a bit
[saartuer.git] / statemachine.py
index e6a27570c45c2731607d95c3f0d9646ff45024db..cb1e4c86b156c94cc15aed4cab418d7345949291 100644 (file)
@@ -12,7 +12,7 @@ def play_sound (what):
                return
        soundfile = SOUNDS_DIRECTORY + what + '/' + random.choice(soundfiles)
        hour = datetime.datetime.time(datetime.datetime.now()).hour
                return
        soundfile = SOUNDS_DIRECTORY + what + '/' + random.choice(soundfiles)
        hour = datetime.datetime.time(datetime.datetime.now()).hour
-       volume = 60 if hour >= 22 or hour <= 6 else 95
+       volume = 60 if hour >= 22 or hour <= 6 else 90
        fire_and_forget_cmd ([SOUNDS_PLAYER, "-volume", str(volume), soundfile], "StateMachine: ")
 
 # convert an absolute nervlist to a relative one
        fire_and_forget_cmd ([SOUNDS_PLAYER, "-volume", str(volume), soundfile], "StateMachine: ")
 
 # convert an absolute nervlist to a relative one
@@ -86,6 +86,7 @@ class StateMachine():
        CMD_LOCK = 5
        CMD_FALLBACK_ON = 6
        CMD_FALLBACK_OFF = 7
        CMD_LOCK = 5
        CMD_FALLBACK_ON = 6
        CMD_FALLBACK_OFF = 7
+       CMD_STATUS = 8
        
        class State():
                def __init__(self, state_machine, nervlist = None):
        
        class State():
                def __init__(self, state_machine, nervlist = None):
@@ -110,6 +111,9 @@ class StateMachine():
                        return StateMachine.StateFallback(self.state_machine)
                def handle_cmd_fallback_off_event(self,arg):
                        arg("412 Precondition Failed: Not in fallback mode!")
                        return StateMachine.StateFallback(self.state_machine)
                def handle_cmd_fallback_off_event(self,arg):
                        arg("412 Precondition Failed: Not in fallback mode!")
+               def handle_cmd_status_event(self,arg):
+                       # TODO use a proper JSON lib
+                       arg('200 okay: {state:\"%s\"}' % self.__class__.__name__)
                def on_leave(self):
                        pass
                def pins(self):
                def on_leave(self):
                        pass
                def pins(self):
@@ -135,6 +139,8 @@ class StateMachine():
                                return self.handle_cmd_fallback_on_event(arg)
                        elif ev == StateMachine.CMD_FALLBACK_OFF:
                                return self.handle_cmd_fallback_off_event(arg)
                                return self.handle_cmd_fallback_on_event(arg)
                        elif ev == StateMachine.CMD_FALLBACK_OFF:
                                return self.handle_cmd_fallback_off_event(arg)
+                       elif ev == StateMachine.CMD_STATUS:
+                               return self.handle_cmd_status_event(arg)
                        else:
                                raise Exception("Unknown command number: %d" % ev)
        
                        else:
                                raise Exception("Unknown command number: %d" % ev)
        
@@ -374,6 +380,6 @@ class StateMachine():
                while newstate is not None:
                        assert isinstance(newstate, StateMachine.State), "I should get a state"
                        self.current_state.on_leave()
                while newstate is not None:
                        assert isinstance(newstate, StateMachine.State), "I should get a state"
                        self.current_state.on_leave()
-                       logger.debug("StateMachine: Doing state transition %s -> %s" % (self.current_state.__class__.__name__, newstate.__class__.__name__))
+                       logger.info("StateMachine: Doing state transition %s -> %s" % (self.current_state.__class__.__name__, newstate.__class__.__name__))
                        self.current_state = newstate
                        newstate = self.current_state.handle_event(StateMachine.CMD_PINS, self.pins)
                        self.current_state = newstate
                        newstate = self.current_state.handle_event(StateMachine.CMD_PINS, self.pins)