Skip to content

Commit

Permalink
Fix bug in confirmation (#91)
Browse files Browse the repository at this point in the history
# Description
Refactors `no.voc` to `cancel.voc` to properly override default vocab
and match spoken instructions
Add max retries to avoid infinite confirmation loop
Display confirmation numbers on screen

# Issues
Closes #90 
Closes #78 

# Other Notes
<!-- Note any breaking changes, WIP changes, requests for input, etc.
here -->

---------

Co-authored-by: Daniel McKnight <daniel@neon.ai>
  • Loading branch information
NeonDaniel and NeonDaniel authored Jun 25, 2024
1 parent db0f898 commit d9b5d50
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
7 changes: 6 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def handle_exit_shutdown_intent(self, message):
:param message: message object associated with request
"""
confirm_number = str(randint(100, 999))
self.gui.show_text(confirm_number,
self.resources.render_dialog("word_confirm"))
validator = numeric_confirmation_validator(confirm_number)
if message.data.get("exit"):
action = SystemCommand.EXIT
Expand All @@ -104,7 +106,10 @@ def handle_exit_shutdown_intent(self, message):
response = self.get_response("ask_exit_shutdown",
{"action": action.value,
"number": confirm_number},
validator, "action_not_confirmed")
validator, "action_not_confirmed",
num_retries=3)
LOG.debug(f"Got response: {response}")
self.gui.clear()
if not response:
self.speak_dialog("confirm_cancel", private=True)
elif response:
Expand Down
1 change: 1 addition & 0 deletions locale/en-us/dialog/word_confirm.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go ahead
3 changes: 2 additions & 1 deletion locale/en-us/vocab/no.voc → locale/en-us/vocab/cancel.voc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ nope
nah
negative
nevermind
never mind
never mind
cancel
1 change: 1 addition & 0 deletions locale/uk-ua/dialog/word_confirm.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
продовжуй
File renamed without changes.
3 changes: 2 additions & 1 deletion test/test_resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ vocab:
- "enable"
- "exit"
- "listening"
- "no"
- "cancel"
- "request"
- "restart"
- "shutdown"
Expand Down Expand Up @@ -54,6 +54,7 @@ dialog:
- confirm_ww_changing
- ask_disable_ww
- confirm_ww_disabled
- word_confirm

# regex entities, not necessarily filenames
regex:
Expand Down
10 changes: 5 additions & 5 deletions test/test_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_handle_exit_shutdown_intent(self):
# Exit Confirmed
message = Message("valid_intent", {"exit": "exit"})

def get_response(*args):
def get_response(*args, **kwargs):
self.assertEqual(args[0], "ask_exit_shutdown")
dialog = args[0]
dialog_data = args[1]
Expand Down Expand Up @@ -102,7 +102,7 @@ def get_response(*args):
# Shutdown confirmed
message = Message("valid_intent", {"shutdown": "shut down"})

def get_response(*args):
def get_response(*args, **kwargs):
self.assertEqual(args[0], "ask_exit_shutdown")
dialog = args[0]
dialog_data = args[1]
Expand Down Expand Up @@ -130,7 +130,7 @@ def get_response(*args):
# Restart Confirmed
message = Message("valid_intent", {"restart": "reboot"})

def get_response(*args):
def get_response(*args, **kwargs):
self.assertEqual(args[0], "ask_exit_shutdown")
dialog = args[0]
dialog_data = args[1]
Expand Down Expand Up @@ -159,7 +159,7 @@ def get_response(*args):
self.skill._do_exit_shutdown.reset_mock()
message = Message("valid_intent", {"exit": "exit"})

def get_response(*args):
def get_response(*args, **kwargs):
self.assertEqual(args[0], "ask_exit_shutdown")
dialog = args[0]
dialog_data = args[1]
Expand All @@ -186,7 +186,7 @@ def get_response(*args):
# Exit no response
message = Message("valid_intent", {"exit": "exit"})

def get_response(*args):
def get_response(*args, **kwargs):
self.assertEqual(args[0], "ask_exit_shutdown")
dialog = args[0]
dialog_data = args[1]
Expand Down

0 comments on commit d9b5d50

Please sign in to comment.