introduced BaseState, which defines default behaviour

This commit is contained in:
Frederic 2015-05-20 00:04:40 +02:00
parent 40eef9aa66
commit cdfb428e00

View file

@ -7,10 +7,12 @@ from tuitest import FeApPinConfiguration, FeApUserInterface
class IllegalEventError(Exception): class IllegalEventError(Exception):
pass pass
class AbstractState(object):
def __init__(self, controller):
self._controller = controller
"""
An abstract state, needed to define all possible events.
"""
class AbstractState(object):
def on_registration_in_progress(self): def on_registration_in_progress(self):
raise IllegalEventError() raise IllegalEventError()
@ -47,7 +49,38 @@ class AbstractState(object):
def on_timeout(self): def on_timeout(self):
raise IllegalEventError() raise IllegalEventError()
class InitState(AbstractState):
"""
The basic state that every other state inherits from. It defines default
behaviour for some events (overriden if necessary).
"""
class BaseState(AbstractState):
def __init__(self, controller):
self._controller = controller
def on_gabelschalter_up(self):
return None
def on_gabelschalter_down(self):
return None
def on_incoming_call(self):
self._controller.get_phone().decline_call()
def on_call_ended(self):
# When an incoming call is declined, a call_ended event occurs, which
# needs to be ignored, here.
return None
def on_nummernschalter_active(self):
return None
def on_nummernschalter_input(self, num):
return None
class InitState(BaseState):
def __init__(self, controller): def __init__(self, controller):
super(InitState, self).__init__(controller) super(InitState, self).__init__(controller)
self._controller.get_feap().set_schauzeichen(True) self._controller.get_feap().set_schauzeichen(True)
@ -56,7 +89,7 @@ class InitState(AbstractState):
print('registration in progress') print('registration in progress')
return RegisteringState return RegisteringState
class RegisteringState(AbstractState): class RegisteringState(BaseState):
def __init__(self, controller): def __init__(self, controller):
super(RegisteringState, self).__init__(controller) super(RegisteringState, self).__init__(controller)
@ -65,7 +98,7 @@ class RegisteringState(AbstractState):
self._controller.get_feap().set_schauzeichen(False) self._controller.get_feap().set_schauzeichen(False)
return IdleState return IdleState
class IdleState(AbstractState): class IdleState(BaseState):
def on_incoming_call(self): def on_incoming_call(self):
print('incomfing call') print('incomfing call')
return SchelltState return SchelltState
@ -74,16 +107,7 @@ class IdleState(AbstractState):
print('gabel up') print('gabel up')
return DialingState return DialingState
def on_gabelschalter_down(self): class SchelltState(BaseState):
pass
def on_nummernschalter_active(self, x):
pass
def on_nummernschalter_input(self, x):
pass
class SchelltState(AbstractState):
def __init__(self, controller): def __init__(self, controller):
super(SchelltState, self).__init__(controller) super(SchelltState, self).__init__(controller)
self._controller.get_feap().set_wecker(True) self._controller.get_feap().set_wecker(True)
@ -99,7 +123,7 @@ class SchelltState(AbstractState):
self.__on_leave() self.__on_leave()
return IdleState return IdleState
class AcceptingState(AbstractState): class AcceptingState(BaseState):
def __init__(self, controller): def __init__(self, controller):
super(AcceptingState, self).__init__(controller) super(AcceptingState, self).__init__(controller)
self._controller.get_phone().accept_call() self._controller.get_phone().accept_call()
@ -107,7 +131,7 @@ class AcceptingState(AbstractState):
def on_call_accepted(self): def on_call_accepted(self):
return CallRunningState return CallRunningState
class CallTerminatingState(AbstractState): class CallTerminatingState(BaseState):
def __init__(self, controller): def __init__(self, controller):
super(CallTerminatingState, self).__init__(controller) super(CallTerminatingState, self).__init__(controller)
self._controller.get_phone().end_call() self._controller.get_phone().end_call()
@ -118,11 +142,11 @@ class CallTerminatingState(AbstractState):
def on_call_accepted(self): def on_call_accepted(self):
return None return None
class ForgottenState(AbstractState): class ForgottenState(BaseState):
def on_gabelschalter_down(self): def on_gabelschalter_down(self):
return IdleState return IdleState
class BusyBeepingState(AbstractState): class BusyBeepingState(BaseState):
def __init__(self, controller): def __init__(self, controller):
super(BusyBeepingState, self).__init__(controller) super(BusyBeepingState, self).__init__(controller)
self._controller.get_phone().play_busy_tone() self._controller.get_phone().play_busy_tone()
@ -137,14 +161,14 @@ class BusyBeepingState(AbstractState):
self.__on_leave() self.__on_leave()
return IdleState return IdleState
class CallRunningState(AbstractState): class CallRunningState(BaseState):
def on_gabelschalter_down(self): def on_gabelschalter_down(self):
return CallTerminatingState return CallTerminatingState
def on_call_ended(self): def on_call_ended(self):
return BusyBeepingState return BusyBeepingState
class WecktState(AbstractState): class WecktState(BaseState):
def on_gabelschalter_down(self): def on_gabelschalter_down(self):
return CallTerminatingState return CallTerminatingState
@ -154,7 +178,7 @@ class WecktState(AbstractState):
def on_call_accepted(self): def on_call_accepted(self):
return CallRunningState return CallRunningState
class ConnectingState(AbstractState): class ConnectingState(BaseState):
def on_gabelschalter_down(self): def on_gabelschalter_down(self):
return CallTerminatingState return CallTerminatingState
@ -171,7 +195,7 @@ class ConnectingState(AbstractState):
def on_call_ended(self): def on_call_ended(self):
return BusyBeepingState return BusyBeepingState
class DialingState(AbstractState): class DialingState(BaseState):
def __init__(self, controller): def __init__(self, controller):
super(DialingState, self).__init__(controller) super(DialingState, self).__init__(controller)
self._controller.get_phone().play_dial_tone() self._controller.get_phone().play_dial_tone()
@ -206,8 +230,6 @@ class DialingState(AbstractState):
self._controller.get_phone().call(self.__number) self._controller.get_phone().call(self.__number)
return ConnectingState return ConnectingState
def on_incoming_call(self):
self._controller.get_phone().decline_call()
class StateMachineController(object): class StateMachineController(object):
def __init__(self, phone, feap): def __init__(self, phone, feap):