class Brain: def __init__(self): # initialize the brain parts self.calendar = Calendar(CalendarClient('*****@*****.**')) self.speak = Speak() self.eyes = Eyes(True) self.eyes.motionDetected += self.__update_last_movement self.eyes.panicDetected += self.__react_on_panic self.last_movement_datetime = datetime.fromisoformat( '1000-01-01T00:00:00+02:00') self.paniced = False # the action rules for the thinking tick self.action_rules = [ GreetingActionRule(self), CloseMeetingActionRule(self, 5), EndingMeetingActionRule(self, 5), ] # current values used in rules self.current_time = self.calendar.get_time_now() self.current_open_events = [] # the timer for the thinking tick self.thinking_tick_timer = RepeatedTimer(5, self.__run_thinking_tick) def start_thinking(self): self.thinking_tick_timer.start() try: logging.info('Roompy is very vigilant') self.eyes.detect() finally: self.thinking_tick_timer.stop() logging.info('Roompy has fallen asleep') def __run_thinking_tick(self): logging.info('running thinking tick') self.current_time = self.calendar.get_time_now() self.current_open_events = self.calendar.get_open_events( self.current_time) logging.info( f'There are {len(self.current_open_events)} current open events.') for action_rule in self.action_rules: action_rule.check_do() def __update_last_movement(self): self.last_movement_datetime = self.calendar.get_time_now() logging.info('last movement updated to {self.last_movement_datetime}') def __react_on_panic(self): # self.speak.speak('DO NOT HIT ME! MY CREATORS WILL FIND OUT ABOUT THIS!') self.paniced = True
def test_get_open_meetings(self): calendar_manager = Calendar(self.calendar_client) result_list = calendar_manager.get_open_events(self.time_now) self.assertEqual(len(result_list), 1)