Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle stop properly and make stateful #113

Open
wants to merge 2 commits into
base: 21.02
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ def initialize(self):
# Longer titles or alternative common names of feeds for searching
self.alt_feed_names = self.translate_namedvalues('alt.feed.name')

self.skill_control.states = {
'inactive':['handle_latest_news'],
'active':['restart_playback']
}
self.skill_control.state = 'inactive'
self.skill_control.category = 'common_play'

def CPS_match_query_phrase(self, phrase):
matched_feed = { 'key': None, 'conf': 0.0 }

Expand Down Expand Up @@ -334,6 +341,21 @@ def get_media_url(self, station_url):
media_url = media_url.split('?')[0]
return media_url

def converse(self, utterances, lang="en-us"):
LOG.debug("NPR converse entered, utterances:%s" % (utterances,))
"""if playing see if user wants to quit"""
# custom stop handler
# note this will work for now but really this should
# be an intent which is enabled while in the active state
# and disabled otherwise
if utterances and self.voc_match(utterances[0], "Stop"):
self.stop()
return True # consume this phrase
else:
self.log.info("NewsSkill:Converse confused by %s - let common play handle it" % (utterances,))

return False # don't consume this phrase

@intent_file_handler("PlayTheNews.intent")
def handle_latest_news_alt(self, message):
# Capture some alternative ways of requesting the news via Padatious
Expand Down Expand Up @@ -389,7 +411,8 @@ def handle_latest_news(self, message=None, feed=None):
self.CPS_send_status(image=image or image_path('generic.png'),
track=self.now_playing)
self.last_message = (True, message)
self.enable_intent('restart_playback')
self.change_state('active')
self.enable_intent('restart_playback') # should be unnecessary

except Exception as e:
self.log.error("Error: {0}".format(e))
Expand All @@ -403,6 +426,7 @@ def restart_playback(self, message):
self.handle_latest_news(self.last_message[1])

def stop(self):
self.change_state('inactive')
# Disable restarting when stopped
if self.last_message:
self.disable_intent('restart_playback')
Expand Down
10 changes: 10 additions & 0 deletions vocab/en-us/Stop.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
silence
quit
end
stop
shut
off
turn
quiet
terminate
abort