Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Candle - the privacy friendly smart home authored Apr 26, 2022
1 parent 62eeb63 commit d2dcd24
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 40 deletions.
36 changes: 23 additions & 13 deletions js/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{'action':'token','token':jwt}

).then((body) => {

console.log("update jwt response: ", body);
}).catch((e) => {
console.log("Error saving token: ", e);
});
Expand Down Expand Up @@ -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'){
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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';
}

Expand Down
45 changes: 20 additions & 25 deletions pkg/voco_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand Down Expand Up @@ -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?")
Expand Down Expand Up @@ -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")



Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}))


Expand Down
15 changes: 13 additions & 2 deletions pkg/voco_api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit d2dcd24

Please sign in to comment.