From 7b15aa13c14e2425eeb2d9b840b8ca8e54cc5350 Mon Sep 17 00:00:00 2001 From: klonfish Date: Tue, 26 May 2015 23:19:26 +0200 Subject: [PATCH] Replaced getters in StateMachineController by properties --- fetapdtest.py | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/fetapdtest.py b/fetapdtest.py index 3c477e7..339b5c6 100644 --- a/fetapdtest.py +++ b/fetapdtest.py @@ -75,7 +75,7 @@ class BaseState(AbstractState): return None def on_incoming_call(self): - self._controller.get_phone().decline_call() + self._controller.phone.decline_call() def on_call_ended(self): # When an incoming call is declined, a call_ended event occurs, which @@ -92,7 +92,7 @@ class BaseState(AbstractState): class InitState(BaseState): def __init__(self, controller): super(InitState, self).__init__(controller) - self._controller.get_feap().set_schauzeichen(True) + self._controller.feap.set_schauzeichen(True) def on_registration_in_progress(self): print('registration in progress') @@ -104,7 +104,7 @@ class RegisteringState(BaseState): def on_registration_successful(self): print('registration successful') - self._controller.get_feap().set_schauzeichen(False) + self._controller.feap.set_schauzeichen(False) return IdleState class IdleState(BaseState): @@ -119,10 +119,10 @@ class IdleState(BaseState): class SchelltState(BaseState): def __init__(self, controller): super(SchelltState, self).__init__(controller) - self._controller.get_feap().set_wecker(True) + self._controller.feap.set_wecker(True) def leave(self): - self._controller.get_feap().set_wecker(False) + self._controller.feap.set_wecker(False) def on_gabelschalter_up(self): return AcceptingState @@ -133,7 +133,7 @@ class SchelltState(BaseState): class AcceptingState(BaseState): def __init__(self, controller): super(AcceptingState, self).__init__(controller) - self._controller.get_phone().accept_call() + self._controller.phone.accept_call() def on_call_accepted(self): return CallRunningState @@ -141,7 +141,7 @@ class AcceptingState(BaseState): class CallTerminatingState(BaseState): def __init__(self, controller): super(CallTerminatingState, self).__init__(controller) - self._controller.get_phone().end_call() + self._controller.phone.end_call() def on_call_ended(self): return IdleState @@ -156,10 +156,10 @@ class ForgottenState(BaseState): class BusyBeepingState(BaseState): def __init__(self, controller): super(BusyBeepingState, self).__init__(controller) - self._controller.get_phone().play_busy_tone() + self._controller.phone.play_busy_tone() def leave(self): - self._controller.get_phone().stop_playing() + self._controller.phone.stop_playing() def on_timeout(self): return ForgottenState @@ -175,6 +175,13 @@ class CallRunningState(BaseState): return BusyBeepingState class WecktState(BaseState): + def __init__(self, controller): + super(WecktState, self).__init__(controller) + self._controller.phone.play_ringback_tone() + + def leave(self): + self._controller.phone.stop_playing() + def on_gabelschalter_down(self): return CallTerminatingState @@ -204,13 +211,13 @@ class ConnectingState(BaseState): class DialingState(BaseState): def __init__(self, controller): super(DialingState, self).__init__(controller) - self._controller.get_phone().play_dial_tone() + self._controller.phone.play_dial_tone() self.__dial_tone = True self.__number = '' def leave(self): if self.__dial_tone: - self._controller.get_phone().stop_playing() + self._controller.phone.stop_playing() self._controller.abort_timeout() def on_gabelschalter_down(self): @@ -219,28 +226,29 @@ class DialingState(BaseState): def on_nummernschalter_active(self): self._controller.abort_timeout() if self.__dial_tone: - self._controller.get_phone().stop_playing() + self._controller.phone.stop_playing() def on_nummernschalter_input(self, num): print('nummernschalter: %d' % (num)) if self.__dial_tone: - self._controller.get_phone().stop_playing() + self._controller.phone.stop_playing() self.__number += str(num) self._controller.abort_timeout() self._controller.set_timeout(5000) def on_timeout(self): print 'Dialing number:', self.__number - self._controller.get_phone().call(self.__number) + self._controller.phone.call(self.__number) return ConnectingState class StateMachineController(object): def __init__(self, phone, feap): - self.__state = InitState(self) self.__phone = phone self.__feap = feap + self.__state = InitState(self) + self.__timeout = None self.__running = True @@ -284,11 +292,13 @@ class StateMachineController(object): self.__timeout.cancel() self.__timeout = None - def get_phone(self): - return phone + @property + def phone(self): + return self.__phone - def get_feap(self): - return feap + @property + def feap(self): + return self.__feap def stop(self, hard=False): if hard: