def acknowledge(self): """Acknowledge a successful request. This method plays a sound to acknowledge a request that does not require a verbal response. This is intended to provide simple feedback to the user that their request was handled successfully. """ audio_file = resolve_resource_file( self.config_core.get('sounds').get('acknowledge')) if not audio_file: LOG.warning("Could not find 'acknowledge' audio file!") return process = play_audio_file(audio_file) if not process: LOG.warning("Unable to play 'acknowledge' audio file!")
def test_play_audio_file(self, mock_subprocess, mock_conf): mock_conf.get.return_value = test_config play_audio_file('indifference.wav') mock_subprocess.Popen.assert_called_once_with( ['mock_wav', 'indifference.wav'], env=Anything()) mock_subprocess.Popen.reset_mock() play_audio_file('praise.mp3') mock_subprocess.Popen.assert_called_once_with( ['mock_mp3', 'praise.mp3'], env=Anything()) mock_subprocess.Popen.reset_mock() mock_conf.get.return_value = test_config play_audio_file('insult.ogg') mock_subprocess.Popen.assert_called_once_with( ['mock_ogg', 'insult.ogg'], env=Anything())
def handle_dataRequest_command(self, message): ''' This function is used to call up the measured values of the sensors. The function works together with the on_message function. Tasmota knows 13 different status queries so far: status (without any digit): a summary of important parameters, status0: playback of all status reports 1-11, status1 to status11: selected single reports e.g. about network settings, sensors or firmware version. Look at the Tasmota documentation for detail. Further down (search for "if sen_name == "), the corresponding keywords are used to filter which status information is retrieved. The following on_message function also filters which values should be announced. ''' req_name = message.data.get("RequestKeyword") sen_name = message.data.get("SensorKeyword") loc_name = message.data.get("LocationKeyword") mdl_name = message.data.get("ModuleKeyword") mdl_name = mdl_name.replace(' ', '_') if mdl_name == "werkstatt_radio": mdl_name = "werkstattradio" if mdl_name == "stromzähler 1": mdl_name = "stromzähler_1" if mdl_name == "stromzähler 2": mdl_name = "stromzähler_2" if mdl_name == "außenthermometer" or mdl_name == "aussenthermometer": mdl_name = "TH10" if self.capitalization: mdl_name = mdl_name.capitalize() if mdl_name == "Th10": mdl_name = "TH10" sen_name = sen_name.capitalize() prefix = "cmnd/" topic = mdl_name + "/" if self.fulltopicsyntax == "default": dataRequestTopic = prefix + topic if self.fulltopicsyntax == "homeassistant": dataRequestTopic = topic + prefix if (self.protocol == "mqtt"): self.mqttc = mqtt.Client("MycroftAI") #if (self.mqttauth == "yes"): #self.mqttc.username_pw_set(self.mqttuser,self.mqttpass) #if (self.mqttssl == "yes"): #self.mqttc.tls_set(self.mqttca) LOGGER.info("Funk Request AJW - connect to: " + str(self.mqtthost)) #LOGGER.info("AJW - connect to: " + str(self.mqttport)) play_audio_file( resolve_resource_file( "/usr/lib/python3.8/site-packages/mycroft/res/snd/verstanden.mp3" )) #self.speak_dialog('verstanden') time.sleep(1) self.mqttc.connect(self.mqtthost, self.mqttport) self.mqttc.on_message = self.on_message self.mqttc.loop_start() if sen_name == "Schaltzustand" or sen_name == "Zustand": command = "STATUS" dataRequestTopic = dataRequestTopic + command payload = 11 if sen_name == "Sensordaten" or sen_name == "Messdaten": command = "STATUS" dataRequestTopic = dataRequestTopic + command payload = 10 if sen_name == "Zeitplan" or sen_name == "Zeitpläne": command = "timers" payload = "" dataRequestTopic = dataRequestTopic + command #self.mqttc.subscribe(str(dataRequestTopic)+"/#") if self.fulltopicsyntax == "default": #self.mqttc.subscribe(result + mdl_name + '/#') self.mqttc.subscribe(self.actionConfirmationTopic) if self.fulltopicsyntax == "homeassistant": #self.mqttc.subscribe(mdl_name + result + '/#') self.mqttc.subscribe(self.actionConfirmationTopic) self.mqttc.publish(dataRequestTopic, payload) LOGGER.info("AJW - Published: " + dataRequestTopic + " " + str(payload)) #self.payload = json.loads(msg.payload.decode()) time.sleep(1) self.mqttc.disconnect() else: self.speak_dialog("not.found", { "command": cmd_name, "action": act_name, "module": dev_name }) LOGGER.error("Error: {0}".format(e))
def handle_automation_command(self, message): ''' The handle_ ... functions include the commands which are when an appropriate combination of required and optional keywords have been specified. Currently the power setting is hard coded. Adaptations are imaginable ''' #Beispiel "Schalte den|die|das <MQTT-Name des Gerätes> an" command = "/POWER" #LOGGER.info('AJW: mqtt automation command') cmd_name = message.data.get("CommandKeyword") mdl_name = message.data.get("ModuleKeyword") mdl_name = mdl_name.replace(' ', '_') if mdl_name == "werkstatt_radio": mdl_name = "werkstattradio" act_name = message.data.get("ActionKeyword") loc_name = message.data.get("LocationKeyword") if loc_name: loc_name = loc_name.replace(' ', '_') else: loc_name = self.default_location if act_name: cmd_name = '/POWER' act_name = act_name.replace('an', 'ON').replace('aus', 'OFF') if (self.protocol == "mqtt"): self.mqttc = mqtt.Client("MycroftAI") #if (self.mqttauth == "yes"): # mqttc.username_pw_set(self.mqttuser,self.mqttpass) #if (self.mqttssl == "yes"): # mqttc.tls_set(self.mqttca) LOGGER.info("AJW - Module automation_command connect to: " + str(self.mqttport)) play_audio_file( resolve_resource_file( "/usr/lib/python3.8/site-packages/mycroft/res/snd/verstanden.mp3" )) #self.speak_dialog('verstanden') time.sleep(1.0) self.mqttc.connect(self.mqtthost, self.mqttport, keepalive=10) self.mqttc.on_message = self.on_message self.mqttc.loop_start() self.mqttc.subscribe(self.actionConfirmationTopic) #LOGGER.info("AJW - connected - about to execute" + "- " + mdl_name + cmd_name) if self.fulltopicsyntax == "default": if self.capitalization: mdl_name = mdl_name.capitalize() self.mqttc.publish(self.prefix + mdl_name + command, act_name) if self.fulltopicsyntax == "homeassistant": if self.capitalization: mdl_name = mdl_name.capitalize() self.mqttc.publish(mdl_name + self.prefix + command, act_name) LOGGER.info("AJW - Published: " + mdl_name + cmd_name, act_name) #allow time for the action to be performed and a confirmation to be returned time.sleep(1) self.mqttc.disconnect() else: self.speak_dialog("not.found", { "command": cmd_name, "action": act_name, "module": dev_name }) LOGGER.error("Error: {0}".format(e))
def handle_record_end(self, message): try: play_audio_file(self.sound) except: play_audio_file(resolve_resource_file("snd/acknowledge.mp3"))
def play_talking_sound(): number = random.randint(1, 19) audio = "/home/alex/mycroft-core/mycroft/res/snd/BD1/Talking/BD1_Talking_{}.wav".format( number) play_audio_file(audio)
def play_short_sound(): number = random.randint(1, 46) audio = "/home/alex/mycroft-core/mycroft/res/snd/BD1/Sounds/BD1_Sounds_{}.wav".format( number) play_audio_file(audio)
def end_recording_sound(self, message): #Plays an audio cue so you know when mycroft is done listening play_audio_file( "/home/alex/mycroft-core/mycroft/res/snd/BD1_end_listening.wav")