Browse Source

added leave() callback to states

pull/1/head
Fr3deric 10 years ago
parent
commit
2789213062
  1. 17
      fetapdtest.py

17
fetapdtest.py

@ -49,6 +49,9 @@ class AbstractState(object): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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)

Loading…
Cancel
Save