def test_set_variabless(self): default_variables = {"coucou": "hello"} with mock.patch("brain.core.ConfigurationManager.SettingLoader" ) as mock_setting_loader: mock_setting_loader.return_value(self.sl) SettingEditor.set_variables(default_variables) self.assertEqual("hello", self.sl.settings.variables["coucou"])
def set_variables(self): """ Set the Brain.ai Core variables value. Can be used with a dictionary of variables : curl -i -H "Content-Type: application/json" --user admin:secret -X POST \ -d '{"variable1":"variables_value","variables_name2":"variables_value2"}' http://127.0.0.1:5000/settings/varaibles """ if not request.get_json(): data = {"Error": "No Parameters provided"} return jsonify(error=data), 400 # get if present value = request.get_json() if not isinstance(value, dict): data = {"Error": "Variables must be a dictionary"} return jsonify(error=data), 400 SettingEditor.set_variables(variables=value) data = {"variables": self.settings.variables} return jsonify(data), 200
def _set_settings(self): # PLAYERS if self.default_player: SettingEditor.set_default_player(self.default_player) if self.players: for player_el in self.players: if isinstance(player_el, dict): for player_name in player_el: name = player_name parameters = player_el[name] new_player = Player(name=name, parameters=parameters) SettingEditor.set_players(new_player) # STT if self.default_stt: SettingEditor.set_default_stt(self.default_stt) if self.speech_to_text: for stt_el in self.speech_to_text: if isinstance(stt_el, dict): for stt_name in stt_el: name = stt_name parameters = stt_el[name] new_stt = Stt(name=name, parameters=parameters) SettingEditor.set_stts(new_stt) # TRIGGER if self.default_trigger: SettingEditor.set_default_trigger(self.default_trigger) if self.triggers: for trigger_el in self.triggers: if isinstance(trigger_el, dict): for trigger_name in trigger_el: name = trigger_name parameters = trigger_el[name] new_trigger = Trigger(name=name, parameters=parameters) SettingEditor.set_trigger(new_trigger) # TTS if self.default_tts: SettingEditor.set_default_tts(self.default_tts) if self.text_to_speech: for tts_el in self.text_to_speech: if isinstance(tts_el, dict): for tts_name in tts_el: name = tts_name parameters = tts_el[name] new_tts = Tts(name=name, parameters=parameters) SettingEditor.set_ttss(new_tts) # Options if self.deaf is not None: signal_order = SignalLauncher.get_order_instance() if signal_order is not None: SettingEditor.set_deaf_status(signal_order.trigger_instance, self.deaf) if self.mute is not None: SettingEditor.set_mute_status(self.mute) if self.energy_threshold is not None: SettingEditor.set_energy_threshold(self.energy_threshold) if self.adjust_for_ambient_noise_second is not None: SettingEditor.set_adjust_for_ambient_noise_second( self.adjust_for_ambient_noise_second) # Hooks if self.hooks: SettingEditor.set_hooks(self.hooks) # Variables if self.var_files: variables = dict() for files in self.var_files: var = Utils.get_real_file_path(files) # var is None has been checked previously in _is_parameters_ok() method variables.update(YAMLLoader.get_config(var)) SettingEditor.set_variables(variables) if self.variable is not None: SettingEditor.set_variables(self.variable)