Commit f65d130e authored by Ralf's avatar Ralf
Browse files

improve statemachine logging

parent 864b9e36
...@@ -103,7 +103,7 @@ class StateMachine(): ...@@ -103,7 +103,7 @@ class StateMachine():
arg("412 Precondition Failed: If not in fallback mode, use the hardware switch to lock the space.") arg("412 Precondition Failed: If not in fallback mode, use the hardware switch to lock the space.")
def handle_cmd_fallback_on_event(self,arg): def handle_cmd_fallback_on_event(self,arg):
arg("200 okay: Entering fallback mode and notifying admins.") arg("200 okay: Entering fallback mode and notifying admins.")
logger.critical("Entering fallback mode. Somebody thinks the hardware sensors are broken.") logger.critical("StateMachine: Entering fallback mode. Somebody thinks the hardware sensors are broken.")
return StateMachine.StateFallback(self.state_machine) return StateMachine.StateFallback(self.state_machine)
def handle_cmd_fallback_off_event(self,arg): def handle_cmd_fallback_off_event(self,arg):
arg("412 Precondition Failed: Not in fallback mode!") arg("412 Precondition Failed: Not in fallback mode!")
...@@ -155,7 +155,7 @@ class StateMachine(): ...@@ -155,7 +155,7 @@ class StateMachine():
self.ledactor().setOff("green") self.ledactor().setOff("green")
def handle_pins_event(self): def handle_pins_event(self):
if not self.pins().door_locked: if not self.pins().door_locked:
logger.info("Door unlocked, space is about to open") logger.info("StateMachine: Door unlocked, space is about to open")
return StateMachine.StateAboutToOpen(self.state_machine) return StateMachine.StateAboutToOpen(self.state_machine)
return super().handle_pins_event() return super().handle_pins_event()
...@@ -166,7 +166,7 @@ class StateMachine(): ...@@ -166,7 +166,7 @@ class StateMachine():
self.ledactor().setOn("green") self.ledactor().setOn("green")
def handle_pins_event(self): def handle_pins_event(self):
if self.pins().door_locked: if self.pins().door_locked:
logger.info("Door locked, closing space") logger.info("StateMachine: Door locked, closing space")
if self.pins().space_active: if self.pins().space_active:
logger.warning("StateMachine: door manually locked, but space switch is still on - going to StateZu nevertheless") logger.warning("StateMachine: door manually locked, but space switch is still on - going to StateZu nevertheless")
play_sound("manual_lock") play_sound("manual_lock")
...@@ -181,13 +181,13 @@ class StateMachine(): ...@@ -181,13 +181,13 @@ class StateMachine():
pins = self.pins() pins = self.pins()
if not (pins.door_locked is None or pins.door_closed is None or pins.space_active is None or pins.bell_ringing is None): if not (pins.door_locked is None or pins.door_closed is None or pins.space_active is None or pins.bell_ringing is None):
if self.fallback: if self.fallback:
logger.info("Going to StateFallback because running in fallback mode") logger.info("StateMachine: Going to StateFallback because running in fallback mode")
return StateMachine.StateFallback(self.state_machine) return StateMachine.StateFallback(self.state_machine)
if pins.door_locked: if pins.door_locked:
logger.info("All sensors got a value, switching to a proper state: Space is closed") logger.info("StateMachine: All sensors got a value, switching to a proper state: Space is closed")
return StateMachine.StateZu(self.state_machine) return StateMachine.StateZu(self.state_machine)
else: else:
logger.info("All sensors got a value, switching to a proper state: Space is (about to) open") logger.info("StateMachine: All sensors got a value, switching to a proper state: Space is (about to) open")
return StateMachine.StateAboutToOpen(self.state_machine) return StateMachine.StateAboutToOpen(self.state_machine)
return super().handle_pins_event() return super().handle_pins_event()
...@@ -207,17 +207,17 @@ class StateMachine(): ...@@ -207,17 +207,17 @@ class StateMachine():
self.ledactor().setState("green", pins.space_active) self.ledactor().setState("green", pins.space_active)
# primitive leaving procedure if space switch turned off # primitive leaving procedure if space switch turned off
if not pins.space_active and old_pins.space_active: if not pins.space_active and old_pins.space_active:
logger.info("StateFallback: Space was disabled, locking the door in {0} seconds".format(FALLBACK_LEAVE_DELAY_LOCK)) logger.info("StateMachine: Space was disabled, locking the door in {0} seconds".format(FALLBACK_LEAVE_DELAY_LOCK))
self._nerver = Nerver([(FALLBACK_LEAVE_DELAY_LOCK, lambda:self.actor().act(Actor.CMD_LOCK))]) self._nerver = Nerver([(FALLBACK_LEAVE_DELAY_LOCK, lambda:self.actor().act(Actor.CMD_LOCK))])
if pins.space_active and not old_pins.space_active: if pins.space_active and not old_pins.space_active:
logger.info("StateFallback: Space was enabled") logger.info("StateMachine: Space was enabled")
if pins.door_locked and not old_pins.door_locked: if pins.door_locked and not old_pins.door_locked:
logger.info("StateFallback: Door got locked") logger.info("StateMachine: Door got locked")
if not pins.door_locked and old_pins.door_locked: if not pins.door_locked and old_pins.door_locked:
logger.info("StateFallback: Door got unlocked") logger.info("StateMachine: Door got unlocked")
if pins.space_active and pins.bell_ringing and not old_pins.bell_ringing: if pins.space_active and pins.bell_ringing and not old_pins.bell_ringing:
# someone just pressed the bell # someone just pressed the bell
logger.info("StateFallback: bell rings, let's buzz") logger.info("StateMachine: bell rings, let's buzz")
self.actor().act(Actor.CMD_BUZZ) self.actor().act(Actor.CMD_BUZZ)
# not calling superclass because we want to stay in fallback mode # not calling superclass because we want to stay in fallback mode
def handle_cmd_unlock_event(self,arg): def handle_cmd_unlock_event(self,arg):
...@@ -232,7 +232,7 @@ class StateMachine(): ...@@ -232,7 +232,7 @@ class StateMachine():
arg("412 Precondition Failed: Fallback mode already active.") arg("412 Precondition Failed: Fallback mode already active.")
def handle_cmd_fallback_off_event(self,arg): def handle_cmd_fallback_off_event(self,arg):
arg("200 okay: Leaving fallback mode and notifying admins.") arg("200 okay: Leaving fallback mode and notifying admins.")
logger.critical("Leaving fallback mode. Somebody thinks the sensors are working again.") logger.critical("StateMachine: Leaving fallback mode. Somebody thinks the sensors are working again.")
return StateMachine.StateStart(self.state_machine) return StateMachine.StateStart(self.state_machine)
class StateZu(AbstractLockedState): class StateZu(AbstractLockedState):
...@@ -240,7 +240,7 @@ class StateMachine(): ...@@ -240,7 +240,7 @@ class StateMachine():
return StateMachine.StateUnlocking(self.state_machine, callback) return StateMachine.StateUnlocking(self.state_machine, callback)
def handle_pins_event(self): def handle_pins_event(self):
if not self.old_pins().space_active and self.pins().space_active: # first thing to check: edge detection if not self.old_pins().space_active and self.pins().space_active: # first thing to check: edge detection
logger.info("Space toggled to active while it was closed - unlocking the door") logger.info("StateMachine: Space toggled to active while it was closed - unlocking the door")
return StateMachine.StateUnlocking(self.state_machine) return StateMachine.StateUnlocking(self.state_machine)
return super().handle_pins_event() return super().handle_pins_event()
...@@ -281,7 +281,7 @@ class StateMachine(): ...@@ -281,7 +281,7 @@ class StateMachine():
nervlist = nervlist_abs2rel([(10 , lambda:play_sound("flipswitch")), nervlist = nervlist_abs2rel([(10 , lambda:play_sound("flipswitch")),
(20 , lambda:play_sound("flipswitch")), (20 , lambda:play_sound("flipswitch")),
(30 , lambda:play_sound("flipswitch")), (30 , lambda:play_sound("flipswitch")),
(30 , lambda:logger.error("Space open but switch not flipped for 30 seconds")), (30 , lambda:logger.error("StateMachine: Space open but switch not flipped for 30 seconds")),
(40 , lambda:play_sound("flipswitch")), (40 , lambda:play_sound("flipswitch")),
(50 , lambda:play_sound("flipswitch")), (50 , lambda:play_sound("flipswitch")),
(60 , lambda:play_sound("flipswitch")), (60 , lambda:play_sound("flipswitch")),
...@@ -293,7 +293,7 @@ class StateMachine(): ...@@ -293,7 +293,7 @@ class StateMachine():
def handle_pins_event(self): def handle_pins_event(self):
pins = self.pins() pins = self.pins()
if pins.space_active: if pins.space_active:
logger.info("Space activated, opening procedure completed") logger.info("StateMachine: Space activated, opening procedure completed")
if not self.old_pins().space_active and random.random() <= SWITCH_PRAISE_PROBABILITY: if not self.old_pins().space_active and random.random() <= SWITCH_PRAISE_PROBABILITY:
play_sound("success") play_sound("success")
return StateMachine.StateAuf(self.state_machine) return StateMachine.StateAuf(self.state_machine)
...@@ -306,7 +306,7 @@ class StateMachine(): ...@@ -306,7 +306,7 @@ class StateMachine():
class StateAuf(AbstractStateWhereUnlockingIsRedundant): class StateAuf(AbstractStateWhereUnlockingIsRedundant):
def __init__(self,sm): def __init__(self,sm):
nervlist = [(24*60*60, lambda: logger.critical("Space is now open for 24h. Is everything all right?"))] nervlist = [(24*60*60, lambda: logger.critical("StateMachine: Space is now open for 24h. Is everything all right?"))]
super().__init__(sm, nervlist) super().__init__(sm, nervlist)
self.last_buzzed = None self.last_buzzed = None
self.api().set_state(True) self.api().set_state(True)
...@@ -357,7 +357,7 @@ class StateMachine(): ...@@ -357,7 +357,7 @@ class StateMachine():
if not self.pins().door_closed: if not self.pins().door_closed:
return StateMachine.StateLeaving(self.state_machine, self.close_attempts) return StateMachine.StateLeaving(self.state_machine, self.close_attempts)
if self.pins().space_active: if self.pins().space_active:
logger.info("Space re-activated, cancelling leaving procedure") logger.info("StateMachine: Space re-activated, cancelling leaving procedure")
return StateMachine.StateAuf(self.state_machine) return StateMachine.StateAuf(self.state_machine)
return super().handle_pins_event() return super().handle_pins_event()
...@@ -368,10 +368,10 @@ class StateMachine(): ...@@ -368,10 +368,10 @@ class StateMachine():
super().__init__(sm, nervlist) super().__init__(sm, nervlist)
def handle_pins_event(self): def handle_pins_event(self):
if self.pins().door_closed: if self.pins().door_closed:
logger.info("The space was left, locking the door") logger.info("StateMachine: The space was left, locking the door")
return StateMachine.StateLocking(self.state_machine, self.close_attempts) return StateMachine.StateLocking(self.state_machine, self.close_attempts)
if self.pins().space_active: if self.pins().space_active:
logger.info("Space re-activated, cancelling leaving procedure") logger.info("StateMachine: Space re-activated, cancelling leaving procedure")
return StateMachine.StateAuf(self.state_machine) return StateMachine.StateAuf(self.state_machine)
return super().handle_pins_event() return super().handle_pins_event()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment