Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
flatsiedatsie authored Nov 23, 2022
1 parent 346660d commit 32da436
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 84 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
}
},
"short_name": "Voco",
"version": "4.0.7",
"version": "4.0.8",
"web_accessible_resources": [
"css/*.css",
"images/*.svg",
Expand Down
88 changes: 66 additions & 22 deletions pkg/intentions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@


def intent_get_time(self, slots, intent_message):
voice_message = ""
if self.DEBUG:
print("__intent_get_time")
try:
Expand All @@ -73,13 +74,16 @@ def intent_get_time(self, slots, intent_message):
except Exception as ex:
print("Error dealing with get_time intent: " + str(ex))

return voice_message



def intent_set_timer(self, slots, intent_message):

if self.DEBUG:
print("__intent_set_timer")

voice_message = ""

try:
sentence = slots['sentence']

Expand All @@ -100,7 +104,7 @@ def intent_set_timer(self, slots, intent_message):
if self.DEBUG:
print("error replacing space in time string")

voice_message = ""

time_delta_voice_message = ""
time_slot_snippet = "" # A snippet from the original sentence that described the time slot.

Expand Down Expand Up @@ -267,17 +271,20 @@ def intent_set_timer(self, slots, intent_message):
except Exception as ex:
print("Error while dealing with timer intent: " + str(ex))

return voice_message



def intent_get_timer_count(self, slots, intent_message):
""" Tells the user how many timers have been set"""

voice_message = ""

try:
if self.DEBUG:
print("Getting the count for: " + str(slots['timer_type']))

voice_message = ""


if slots['timer_type'] == None:
if self.DEBUG:
Expand Down Expand Up @@ -321,19 +328,22 @@ def intent_get_timer_count(self, slots, intent_message):
except Exception as ex:
print("Error while dealing with get_timer_count intent: " + str(ex))

return "Sorry, there was an error. "
return voice_message
#return "Sorry, there was an error. "



def intent_list_timers(self, slots, intent_message):
""" Tells the user details about their timers/reminders"""

voice_message = ""

try:

if self.DEBUG:
print("Listing all timers for timer type: " + str(slots['timer_type']))

voice_message = ""


if slots['timer_type'] == None:
if self.DEBUG:
Expand Down Expand Up @@ -439,21 +449,22 @@ def intent_list_timers(self, slots, intent_message):
except Exception as ex:
print("Error while dealing with list_timers intent: " + str(ex))

return "Sorry, there was an error. "
return voice_message
#return "Sorry, there was an error. "



def intent_stop_timer(self, slots, intent_message):
"""Remove all, the last, or a specific number of timers"""

voice_message = ""
try:

if slots['number'] == 0: # If the user mentions 'zero' in the command, it most likely means he/she wants to remove all timers
slots['timer_last'] = "all"

removed_timer_count = 0

voice_message = ""


if slots['timer_type'] == None:
if self.DEBUG:
Expand Down Expand Up @@ -603,7 +614,8 @@ def intent_stop_timer(self, slots, intent_message):
except Exception as ex:
print("Error in stop_timer: " + str(ex))

return "Sorry, there was an error. "
return voice_message
#return "Sorry, there was an error. "



Expand Down Expand Up @@ -755,7 +767,8 @@ def intent_get_boolean(self, slots, intent_message, found_properties):
except Exception as ex:
print("Error in intent_get_boolean: " + str(ex))

return "Sorry, there was an error. "
return voice_message
#return "Sorry, there was an error. "

#voice_message = clean_up_string_for_speaking(voice_message)
#if self.DEBUG:
Expand All @@ -780,7 +793,8 @@ def intent_get_value(self, slots, intent_message,found_properties):
for found_property in found_properties:


print("str(found_property['property']).lower(): " + str(found_property['property']).lower() )
if self.DEBUG:
print("str(found_property['property']).lower(): " + str(found_property['property']).lower() )



Expand All @@ -804,6 +818,8 @@ def intent_get_value(self, slots, intent_message,found_properties):
#print("get_value is looping over property: " + str(found_property))

if found_property['type'] == 'boolean' and len(found_properties) > 1: # Skip booleans if we can.
if self.DEBUG:
print("intent_get_value: skipping boolean (how did this even end up in the list?)")
continue

api_path = str(found_property['property_url'])
Expand All @@ -819,7 +835,8 @@ def intent_get_value(self, slots, intent_message,found_properties):
continue

except:
print("get_value: could not compare returned json to {}")
if self.DEBUG:
print("get_value: error, skipping. Could not compare returned json to {}")
continue

try:
Expand All @@ -841,10 +858,20 @@ def intent_get_value(self, slots, intent_message,found_properties):

api_value = api_result[key]

if str(api_value) == "" or api_value == 204:
if self.DEBUG:
print("WARNING, api_value is empty string or 204 error code.")
if len(found_properties) > 1:
continue
else:
api_value = "unknown"



if str(api_value) != "":

if self.DEBUG:
print("api_result[key] = " + str(api_result[key]))
print("got api_result[key] = " + str(api_result[key]))

if api_value == None:
if self.DEBUG:
Expand All @@ -861,9 +888,14 @@ def intent_get_value(self, slots, intent_message,found_properties):
if found_property['property'] not in str(found_property['thing']):
voice_message += str(found_property['property'])
if found_property['thing'] != None:
if voice_message != "" and str(found_property['thing']) not in str(found_property['property']): # not str(found_property['property']).endswith( str(found_property['thing']) )
if voice_message != "" and str(found_property['thing']) not in str(found_property['property']): # not str(found_property['property']).endswith( str(found_property['thing']) ) # TODO: isn't this the other way around? That the property title should not be in the thing title?
voice_message += " of "
voice_message += str(found_property['thing'])
else:
if self.DEBUG:
print("Not adding thing title to voice message. Reason: voice message was not empty (" + str(voice_message) + ") or property title was in thing title.")
if voice_message == "":
voice_message += "It"
voice_message += " is "

elif len(found_properties) > 3:
Expand Down Expand Up @@ -906,6 +938,10 @@ def intent_get_value(self, slots, intent_message,found_properties):
print("string len(api_result[key]) = " + str(len(api_value)))
if len(api_value) == 7 and api_value.startswith('#'): # hex color value
voice_message = "The color is " + str(hex_to_color_name(api_value))
elif api_value == 'ON':
voice_message += "on"
elif api_value == 'OFF':
voice_message += "off"
else:
voice_message += str(api_value)

Expand Down Expand Up @@ -969,7 +1005,8 @@ def intent_get_value(self, slots, intent_message,found_properties):
except Exception as ex:
print("Error in intent_get_value: " + str(ex))

return "Sorry, there was an error. "
return voice_message
#return "Sorry, there was an error. "



Expand All @@ -989,11 +1026,14 @@ def intent_set_state(self, slots, intent_message, found_properties, delayed_acti
intent_message['origin'] = 'voice'
"""

sentence = slots['sentence']

double_time = False

voice_message = ""

try:

sentence = slots['sentence']

if slots['boolean'] is None:
if self.DEBUG:
print("Error, no boolean set")
Expand All @@ -1011,7 +1051,7 @@ def intent_set_state(self, slots, intent_message, found_properties, delayed_acti
if delayed_action != None:
slots['boolean'] = delayed_action

voice_message = ""

back = "" # used when the voice message should be 'back to', as in "switching back to off.


Expand Down Expand Up @@ -1403,7 +1443,8 @@ def intent_set_state(self, slots, intent_message, found_properties, delayed_acti
except Exception as ex:
print("Error in intent_set_state: " + str(ex))

return "Sorry, there was an error. "
return voice_message
#return "Sorry, there was an error. "


def intent_set_value(self, slots, intent_message, found_properties, original_value=None):
Expand All @@ -1418,7 +1459,7 @@ def intent_set_value(self, slots, intent_message, found_properties, original_val
print("slots: " + str(slots))
print("")

sentence = slots['sentence']

voice_message = ""
desired_value = None
back = ""
Expand All @@ -1427,6 +1468,9 @@ def intent_set_value(self, slots, intent_message, found_properties, original_val


try:

sentence = slots['sentence']

# Select the desired value from the intent data

if slots['color'] != None:
Expand Down Expand Up @@ -1844,8 +1888,8 @@ def intent_set_value(self, slots, intent_message, found_properties, original_val
except Exception as ex:
print("Error in intent_set_value: " + str(ex))

return "Sorry, there was an error. "

#return "Sorry, there was an error. "
return voice_message
# this works on the basis of a capability only.
#def mass_set_state(self, slots):

Expand Down
2 changes: 2 additions & 0 deletions pkg/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ def clean_up_string_for_speaking(sentence): # Also used in thing scanner!
#print("cleaning up: " + str(sentence))
if len(sentence):
sentence = re.sub(r"(\s\-[0-9]+)", replace_dash_with_minus, sentence)
sentence = sentence.replace('color temp ', 'color temperature ')

sentence = sentence.replace('/', ' ')
sentence = sentence.replace('\\', ' ')
sentence = sentence.replace('+', ' plus ')
Expand Down
Loading

0 comments on commit 32da436

Please sign in to comment.