예제 #1
0
 def register_card_usage(self, card_guid):
     """
     Send query to server about card usage
     :param card_guid: used card GUID
     """
     ui.show_data(ui.CARD_SCANNED)
     self.query_card_usage(card_guid, self.__term_guid)
예제 #2
0
 def wait_for_server_response(self):
     """
     Waiting for response from server (Every 2 seconds send query about terminals until dont get this one from server)
     """
     ui.show_data(ui.WAITING_FOR_SERVER)
     while self.__term_list is None:
         time.sleep(2)
         self.query_available_terminals()
예제 #3
0
 def check_any_terminal_registered(self):
     """
     Check if at least one terminal is added in database. If not then exit program
     :return: True - at least one terminal is added in database, False - otherwise
     """
     if len(self.__term_list) == 0:
         ui.show_data(ui.NOT_FOUND_TERMINAL)
         ui.read_data(ui.INPUT_WAITING)
         exit(0)
예제 #4
0
 def read_terminal(self):
     """
     Waiting for message from server about terminals, ask for choosing one of available
     and send message to server about ID of chosen terminal
     """
     self.wait_for_server_response()
     self.check_any_terminal_registered()
     ui.show_data(ui.TERMINALS_READED)
     self.__term_guid = self.choose_terminal()
     query = TERM_SELECTED_QUERY + "." + "ID of connected terminal:." + self.__term_guid
     self.__client.publish(self.config["server_topic"], query)
예제 #5
0
 def scan_card(self):
     """
     Scan and return card GUID - temporary mocked to read RFID card code from user console
     :return: used card GUID
     """
     prompt = "Temporary mocked - put card id from keyboard or nothing to exit: "
     user_input = ui.read_data(prompt)
     while not user_input.isdigit() and not user_input == EXIT_BTN:
         ui.show_data(ui.WRONG_CARD_GUID)
         user_input = ui.read_data(prompt)
     return user_input
예제 #6
0
 def run(self):
     """
     Run client application. Executed in loop until specific exit input not given
     """
     self.setup()
     self.read_terminal()
     while self.__client_active:
         ui.show_data(ui.SCAN_CARD_PROMPT)
         card_guid = self.scan_card()
         self.__client_active = not card_guid == EXIT_BTN
         if card_guid != EXIT_BTN:
             self.register_card_usage(card_guid)
     self.disconnect_from_broker()
예제 #7
0
    def choose_terminal(self):
        """
        Read terminal GUID until not find it in database
        :return: Terminal from database with given GUID from user input
        """
        ui.show_data(ui.TERMINALS_MENU)
        ui.show_data(self.__term_list)

        term_guid = ui.read_data(ui.TERMINAL_INPUT)
        while term_guid not in self.__term_list:
            ui.show_data(term_guid + ": " + ui.INCORRECT_TERMINAL + "\n" + ui.SEPARATOR + "\n" + ui.TERMINALS_MENU)
            ui.show_data(self.__term_list)
            term_guid = ui.read_data(ui.TERMINAL_INPUT)
        return term_guid