Beispiel #1
0
 def test_ChangeCodeState_correct_confirmation(self):
     fsm = FSMController()
     state = ChangeCodeState(fsm)
     state = state.process_input('4')
     state = state.process_input('5')
     state = state.process_input('6')
     state = state.process_input('#')  # any non-numeric completes the code
     state = state.process_input('4')
     state = state.process_input('5')
     state = state.process_input('6')  # confirm the code
     self.assertEqual("456", fsm.get_correct_code())
     # Check that we returned to the initial state
     next_state = state.process_input('1')
     self.assertIsInstance(next_state, InputCodeState)
Beispiel #2
0
 def test_shutdown_lights(self):
     fsm = FSMController()
     state = LoggedInState(fsm)
     with patch.object(fsm, 'show_shutdown_lights') as mock:
         state = state.process_input('0')
         state = state.process_input('#')
     mock.assert_called_once_with()
Beispiel #3
0
 def test_InputCodeState_incorrect_code(self):
     fsm = FSMController()
     correct_code = "123"
     state = InputCodeState(fsm, correct_code)
     state = state.process_input('1')
     state = state.process_input('1')
     state = state.process_input('1')
     self.assertIsInstance(state, RecieveInputState)
Beispiel #4
0
 def test_InputCodeState_correct_code(self):
     fsm = FSMController()
     correct_code = "123"
     state = InputCodeState(fsm, correct_code)
     state = state.process_input('1')
     state = state.process_input('2')
     state = state.process_input('3')
     # Correct code input should result in the logged in state
     self.assertIsInstance(state, LoggedInState)
Beispiel #5
0
 def test_login_failed_lights(self):
     fsm = FSMController()
     correct_code = "123"
     state = InputCodeState(fsm, correct_code)
     with patch.object(fsm, 'show_error_lights') as mock:
         state = state.process_input('6')
         state = state.process_input('6')
         state = state.process_input('6')
     mock.assert_called_once_with()
Beispiel #6
0
 def test_LoggedInState_abort(self):
     fsm = FSMController()
     state = LoggedInState(fsm)
     state = state.process_input('1')
     state = state.process_input('*')  # Abort
     self.assertIsInstance(state, LoggedInState)
     state = state.process_input('0')
     state = state.process_input('#')
     # Action 0 should return to the sleeping state
     self.assertIsInstance(state, SleepingState)
Beispiel #7
0
 def test_LoggedInState_do_action(self):
     fsm = FSMController()
     state = LoggedInState(fsm)
     state = state.process_input('0')
     state = state.process_input('#')
     # Action 0 should return to the sleeping state
     self.assertIsInstance(state, SleepingState)
     state = LoggedInState(fsm)
     state = state.process_input('1')
     state = state.process_input('#')
     # Action 1 should enter GetLedIdState
     self.assertIsInstance(state, GetLedIdState)
Beispiel #8
0
 def test_ChangeCodeState_incorrect_confirmation(self):
     fsm = FSMController()
     state = ChangeCodeState(fsm)
     state = state.process_input('4')
     state = state.process_input('5')
     state = state.process_input('6')
     state = state.process_input('#')  # any non-numeric completes the code
     state = state.process_input('1')
     state = state.process_input('2')
     state = state.process_input('3')  # incorrect confirmation of the code
     # Incorrect confirmation should return to the initial state
     self.assertIsInstance(state, RecieveInputState)
Beispiel #9
0
 def test_led_lights(self):
     fsm = FSMController()
     state = GetLedIdState(fsm)
     with patch.object(fsm, 'set_led') as mock:
         state = state.process_input('1')
         state = state.process_input('#')  # End led id input
         self.assertIsInstance(state, GetLedDurationState)
         self.assertEqual(state._led_id, 1)  # LED id should be 1
         state = state.process_input("5")
         state = state.process_input("#")  # End led duration input
     # set led should be called with id 1 and duration 5
     mock.assert_called_once_with(1, 5)
     # Should return to the logged in state
     self.assertIsInstance(state, LoggedInState)
Beispiel #10
0
class KPC:
    def __init__(self):
        self._fsm = FSMController()
        self._fsm.set_state(SleepingState(self._fsm))
        self._fsm.set_correct_code("0000")
        self._running = False
        self._keypad = Keypad()

    def _main_loop(self):
        while self._running:
            input = self._keypad.wait_for_next_signal()
            self._fsm.process_input(input)

    def start(self):
        self._running = True
        self._main_loop()
Beispiel #11
0
 def __init__(self):
     self._fsm = FSMController()
     self._fsm.set_state(SleepingState(self._fsm))
     self._fsm.set_correct_code("0000")
     self._running = False
     self._keypad = Keypad()
Beispiel #12
0
 def test_RecieveInputState_number_input(self):
     fsm = FSMController()
     state = RecieveInputState(fsm)
     next_state = state.process_input('1')
     self.assertIsInstance(next_state, InputCodeState)
Beispiel #13
0
 def test_startup_lights(self):
     fsm = FSMController()
     state = SleepingState(fsm)
     with patch.object(fsm, 'show_startup_lights') as mock:
         state = state.process_input('1')
     mock.assert_called_once_with()
Beispiel #14
0
 def __init__(self, fsm: FSMController, new_code: str):
     super().__init__(fsm)
     print("updating new code...")
     fsm.set_correct_code(new_code)