def send_client_event_config_write(self, client_id: str, config: dict): """ Sends a request to write a event config to a client :param client_id: ID of the client to send the config to :param config: Config to write :return: None :raises UnknownClientException: If client id is unknown to the system :raises ConfigWriteError: If client did not acknowledge config writing success :raises ValidationError: If passed config was faulty """ if client_id not in [x.get_name() for x in self._delegate.get_client_info()]: raise UnknownClientException(client_id) writer = ClientController(client_id, self._network) writer.write_event_config(config)
def _write_config(self): manager = ClientConfigManager() config_names = manager.get_config_names() config_path: Optional[str] config_data: Optional[dict] = None while not config_data: config_index = select_option(config_names, "which config to write", "Quit") if config_index == -1: return config_data = manager.get_config(config_names[config_index]) if not config_data: response = ask_for_continue( "Config file could either not be loaded, isn no valid json file or" "no valid config. Try again?") if not response: return else: continue print(f"Loaded config '{config_data['name']}'") print() print("Writing config:") write_controller = ClientController(self._client_name, self._network) w_system = False w_event = False w_gadget = False has_error = False write_option = select_option([ "Write complete config", "System only", "Gadgets only", "Events only" ], "writing task", "back") if write_option == -1: return elif write_option == 0: w_system = True w_event = True w_gadget = True elif write_option == 1: w_system = True elif write_option == 2: w_gadget = True elif write_option == 3: w_event = True if w_system: print("Writing system config...") try: with LoadingIndicator(): write_controller.write_system_config(config_data["system"]) print("Config was successfully written\n") except NoClientResponseException: print("Received no response to config write request\n") has_error = True except ConfigWriteError: print("Failed to write config on chip\n") has_error = True if w_gadget: print("Writing gadget config...") try: with LoadingIndicator(): write_controller.write_gadget_config( config_data["gadgets"]) print("Config was successfully written\n") except NoClientResponseException: print("Received no response to config write request\n") has_error = True except ConfigWriteError: print("Failed to write config on chip\n") has_error = True if w_event: print("Writing event config...") try: with LoadingIndicator(): write_controller.write_event_config(config_data["events"]) print("Config was successfully written\n") except NoClientResponseException: print("Received no response to config write request\n") has_error = True except ConfigWriteError: print("Failed to write config on chip\n") has_error = True if not has_error: print("All writing efforts were successful\n") else: print("Completed with errors\n")