mycroft-core icon indicating copy to clipboard operation
mycroft-core copied to clipboard

Add ask_confirm method

Open krisgesling opened this issue 3 years ago • 9 comments

Adds a new method, ask_confirm(), an alternative to ask_yesno that returns only a Boolean or None.

closes #2835 replacing PR #2837

if self.ask_confirm('question'):
    self.speak("got it")
else:
    self.speak("task failed successfully")

This PR also adds an Enum to make ask_yesno somewhat more language agnostic which was part of the original issue

result = self.ask_yesno(...)
if result == UserReply.YES:
    self.speak("you agree with me")
elif result == UserReply.NO:
    self.speak("you do not agree with me")
elif result is None:
    self.speak("you did not answer")
else:
    self.speak("stay on topic you fool")

The Enum is backwards compatible with raw string comparisons

assert "yes" == UserReply.YES
assert "no" == UserReply.NO

krisgesling avatar Mar 11 '21 05:03 krisgesling

Just been on a test writing spree and this came to mind so I've extended Ake's new tests to cover ask_confirm()

krisgesling avatar Mar 11 '21 05:03 krisgesling

Voight Kampff Integration Test Succeeded (Results)

devops-mycroft avatar Mar 11 '21 05:03 devops-mycroft

I'm torn as to whether None is necessary. On the one hand, it's a natural and useful distinction. On the other hand, in a confirmation prompt, aren't "No" and "Cancel" basically the same operation?

If ask_yesno() is being retained, then, imo, the "intended" use cases are like,

ask_yesno("Overwrite the existing file?") (True overwrites file, False keeps file, else cancel operation) ask_confirm("This operation will overwrite the existing file. Should we continue?") (True continues, False cancels the operation, clicking the 'X' on the UI popup cancels the operation. Does it need an additional 'cancel' button?)

ChanceNCounter avatar Mar 11 '21 18:03 ChanceNCounter

None identifies a STT failure

JarbasAl avatar Mar 11 '21 19:03 JarbasAl

None could identify a number of things, but I think they all constitute a "cancel" condition in a confirmation prompt.

ChanceNCounter avatar Mar 11 '21 19:03 ChanceNCounter

None is still falsey so you can do:

if ask_confirm('question'):
    # Confirmed
else:
    # Either explicitly no, or None

The bigger difference here is that ask_yesno() will return the full utterance if neither "yes" nor "no" is detected. Hence an answer of "bananas" would be a truthy value.

krisgesling avatar Mar 12 '21 02:03 krisgesling

Voight Kampff Integration Test Failed (Results). Mycroft logs are also available: skills.log, audio.log, voice.log, bus.log, enclosure.log

devops-mycroft avatar May 28 '21 12:05 devops-mycroft

Voight Kampff Integration Test Failed (Results). Mycroft logs are also available: skills.log, audio.log, voice.log, bus.log, enclosure.log

devops-mycroft avatar May 28 '21 23:05 devops-mycroft

Voight Kampff Integration Test Succeeded (Results)

devops-mycroft avatar May 30 '21 23:05 devops-mycroft