From d2dcd24d6bd8dd577986258936fed8b07a2a9283 Mon Sep 17 00:00:00 2001 From: Candle - the privacy friendly smart home <39312291+createcandle@users.noreply.github.com> Date: Tue, 26 Apr 2022 18:41:21 +0200 Subject: [PATCH] Add files via upload --- js/extension.js | 36 +++++++++++++++++++++------------ pkg/voco_adapter.py | 45 ++++++++++++++++++----------------------- pkg/voco_api_handler.py | 15 ++++++++++++-- 3 files changed, 56 insertions(+), 40 deletions(-) diff --git a/js/extension.js b/js/extension.js index 47a5472d..a5c1a132 100644 --- a/js/extension.js +++ b/js/extension.js @@ -29,7 +29,7 @@ {'action':'token','token':jwt} ).then((body) => { - + console.log("update jwt response: ", body); }).catch((e) => { console.log("Error saving token: ", e); }); @@ -270,6 +270,17 @@ document.getElementById('extension-voco-content').classList.add('extension-voco-show-tab-satellites'); } } + else{ + // Not a satellite, so succesful injection matters + if('possible_injection_failure' in body && 'mqtt_connected' in body){ + if(body.mqtt_connected == false){ + //document.getElementById("extension-voco-mqtt-error").style.display = 'block'; + } + else if(body.possible_injection_failure){ + document.getElementById("extension-voco-injection-failure").style.display = 'block'; + } + } + } if('hostname' in body){ if(body['hostname'] == 'gateway' || body['hostname'] == 'candle'){ @@ -309,14 +320,7 @@ } - if('possible_injection_failure' in body && 'mqtt_connected' in body){ - if(body.mqtt_connected == false){ - //document.getElementById("extension-voco-mqtt-error").style.display = 'block'; - } - else if(body.possible_injection_failure){ - document.getElementById("extension-voco-injection-failure").style.display = 'block'; - } - } + // Remove spinner @@ -481,12 +485,18 @@ this.items_list = body['items']; this.current_time = body['current_time']; - if(body['initial_injection_completed']){ - document.getElementById('extension-voco-injection-busy').style.display = 'none'; - document.getElementById('extension-voco-text-commands-container').style.display = 'block'; + if(body['is_satellite'] == false){ + if(body['initial_injection_completed']){ + document.getElementById('extension-voco-injection-busy').style.display = 'none'; + document.getElementById('extension-voco-text-commands-container').style.display = 'block'; + } + else{ + document.getElementById('extension-voco-injection-busy').style.display = 'block'; + document.getElementById('extension-voco-text-commands-container').style.display = 'none'; + } } else{ - document.getElementById('extension-voco-injection-busy').style.display = 'block'; + document.getElementById('extension-voco-injection-busy').style.display = 'none'; document.getElementById('extension-voco-text-commands-container').style.display = 'none'; } diff --git a/pkg/voco_adapter.py b/pkg/voco_adapter.py index 935766bf..3a0e9e5a 100644 --- a/pkg/voco_adapter.py +++ b/pkg/voco_adapter.py @@ -2002,11 +2002,11 @@ def clock(self, voice_messages_queue): if time.time() - self.addon_start_time > 120: self.still_busy_booting = False - if self.initial_injection_completed == False: + if self.initial_injection_completed == False and self.persistent_data['is_satellite'] == False: self.possible_injection_failure = True - if time.time() - self.addon_start_time > 240 and self.initial_injection_completed == False: - print("Error. Voco failed to load properly. Attempting reboot of addon") + if time.time() - self.addon_start_time > 240 and self.initial_injection_completed == False and self.persistent_data['is_satellite'] == False: + print("Error. Voco failed to load properly. Attempting complete reboot of addon") self.close_proxy() if self.still_busy_booting == False: @@ -2026,22 +2026,14 @@ def clock(self, voice_messages_queue): self.run_snips() - # If (part of) Snips has crashed, and there is no valid reason for snips to be down, try and restart it. - # - if the microphone is disconnected, then there is no need to restart snips straight away - # - if we're a satellite, Voco will already be restarted at voco attempt 5 - # - if we're a satellite, and we lost connection to the main server, there is no need to enable snips, as it won't be able to connect to the main MQTT server - elif self.is_snips_running() < 7 and self.missing_microphone == False and self.periodic_voco_attempts < 4 and self.currently_scanning_for_missing_mqtt_server == False: - if self.DEBUG: - print("clock thread is attempting to restart snips") - self.set_status_on_thing("restarting") - self.run_snips() - + else: if self.initial_injection_completed == False and self.injection_in_progress == False: if self.DEBUG: print("Clock: attempting a forced injection since no injection complete message was received yet") - self.inject_updated_things_into_snips(True) # Force a new injection until it sticks + if self.persistent_data['is_satellite'] == False: + self.inject_updated_things_into_snips(True) # Force a new injection until it sticks #print("snips did not need to be restarted") @@ -2145,13 +2137,16 @@ def clock(self, voice_messages_queue): else: if self.DEBUG: - print("still busy booting?? self.mqtt_connected_succesfully_at_least_once: " + str(self.mqtt_connected_succesfully_at_least_once)) + print("still busy booting?? self.mqtt_connected_succesfully_at_least_once?: " + str(self.mqtt_connected_succesfully_at_least_once)) if self.injection_in_progress == False and self.mqtt_connected == True: - if self.DEBUG: - print("Clock: attempting a forced injection since no injection complete message was received yet") - self.inject_updated_things_into_snips(True) # Force a new injection until it sticks - - + if self.persistent_data['is_satellite'] == False: + if self.DEBUG: + print("Clock: attempting a forced injection since no injection complete message was received yet") + self.inject_updated_things_into_snips(True) # Force a new injection until it sticks + elif self.satellite_should_act_on_intent: + if self.DEBUG: + print("Clock: attempting a forced injection on a satellite with intention recognition since no injection complete message was received yet") + self.inject_updated_things_into_snips(True) # Force a new injection until it sticks else: if self.DEBUG: print("WARNING: clock: still no mqtt client?") @@ -2499,14 +2494,14 @@ def clock(self, voice_messages_queue): print("clock: second opinion on Snips being down: self.is_snips_running() count: " + str(alternative_process_counter)) if self.persistent_data['is_satellite']: - if alternative_process_counter == 0: + if alternative_process_counter < 2: # == 0: if self.DEBUG: - print("conclusion: snips should be restarted") + print("conclusion: snips satellite should be restarted") self.should_restart_snips = True elif alternative_process_counter < 7: self.should_restart_snips = True if self.DEBUG: - print("conclusion: snips should be restarted") + print("conclusion: snips coordinator should be restarted") @@ -2658,7 +2653,7 @@ def cancel_pairing(self): def unload(self): if self.DEBUG: print("") - print("Shutting down Voco.") + print("In unload. Shutting down Voco.") print("") if self.matrix_started: @@ -3450,7 +3445,7 @@ def on_message(self, client, userdata, msg): if 'siteId' in payload: if payload['siteId'] == self.persistent_data['site_id']: self.mute() - elif not self.persistent_data['is_satellite']: + elif self.persistent_data['is_satellite'] == False: self.mqtt_client.publish("hermes/voco/" + str(payload['siteId']) + "/mute",json.dumps({"mute":True})) diff --git a/pkg/voco_api_handler.py b/pkg/voco_api_handler.py index 8ef9ec20..ddcc4231 100644 --- a/pkg/voco_api_handler.py +++ b/pkg/voco_api_handler.py @@ -326,9 +326,19 @@ def handle_request(self, request): print("Handling request to /init") try: - #self.adapter.token = str(request.body['jwt']) - #self.adapter.persistent_data['token'] = str(request.body['jwt']) + if 'jwt' in request.body: + #self.adapter.token = str(request.body['jwt']) + #self.adapter.persistent_data['token'] = str(request.body['jwt']) + + token = str(request.body['jwt']) + token = token.replace("\n", "") + if self.DEBUG: + print("incoming token is: " + str(token)) + if len(token) > 30: + self.adapter.token = token + self.adapter.persistent_data['token'] = token + self.adapter.save_persistent_data() # reset text response in UI self.adapter.last_text_response = "" @@ -499,6 +509,7 @@ def handle_request(self, request): 'matrix_logged_in': self.adapter.matrix_logged_in, 'matrix_busy_registering':self.adapter.matrix_busy_registering, 'user_account_created':self.adapter.user_account_created}), + 'is_satellite':self.adapter.persistent_data['is_satellite'] ) except Exception as ex: print("Error getting init data: " + str(ex))