From 27892130625131e9fdde171bb235ea9416f3c18a Mon Sep 17 00:00:00 2001 From: Frederic Date: Wed, 20 May 2015 00:20:50 +0200 Subject: [PATCH] added leave() callback to states --- fetapdtest.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fetapdtest.py b/fetapdtest.py index 19808c8..10918d4 100644 --- a/fetapdtest.py +++ b/fetapdtest.py @@ -49,6 +49,9 @@ class AbstractState(object): def on_timeout(self): raise IllegalEventError() + def leave(self): + return None + """ The basic state that every other state inherits from. It defines default @@ -112,15 +115,13 @@ class SchelltState(BaseState): super(SchelltState, self).__init__(controller) self._controller.get_feap().set_wecker(True) - def __on_leave(self): + def leave(self): self._controller.get_feap().set_wecker(False) def on_gabelschalter_up(self): - self.__on_leave() return AcceptingState def on_call_ended(self): - self.__on_leave() return IdleState class AcceptingState(BaseState): @@ -151,14 +152,13 @@ class BusyBeepingState(BaseState): super(BusyBeepingState, self).__init__(controller) self._controller.get_phone().play_busy_tone() - def __on_leave(self): + def leave(self): self._controller.get_phone().stop_playing() def on_timeout(self): return ForgottenState def on_gabelschalter_down(self): - self.__on_leave() return IdleState class CallRunningState(BaseState): @@ -202,13 +202,12 @@ class DialingState(BaseState): self.__dial_tone = True self.__number = '' - def __on_leave(self): + def leave(self): if self.__dial_tone: self._controller.get_phone().stop_playing() self._controller.abort_timeout() def on_gabelschalter_down(self): - self.__on_leave() return IdleState def on_nummernschalter_active(self): @@ -225,7 +224,6 @@ class DialingState(BaseState): self._controller.set_timeout(5000) def on_timeout(self): - self.__on_leave() print 'Dialing number:', self.__number self._controller.get_phone().call(self.__number) return ConnectingState @@ -259,6 +257,9 @@ class StateMachineController(object): if not newstate: continue + self.__state.leave() + self.abort_timeout() + oldstate = self.__state.__class__ print('%s -> %s' % (oldstate.__name__, newstate.__name__)) self.__state = newstate(self)