Skip to content

Commit

Permalink
Merge pull request MycroftAI#34 from forslund/feature/disable-chirp-o…
Browse files Browse the repository at this point in the history
…n-unknown

Disable chirp on unknown
  • Loading branch information
krisgesling authored Jun 26, 2020
2 parents 3435fa4 + 1a5b3dc commit 869b316
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,31 @@


class NapTimeSkill(MycroftSkill):
"""
Skill to handle mycroft speech client listener sleeping and
awakening.
"""
"""Skill to handle mycroft speech client listener sleeping."""
def initialize(self):
self.started_by_skill = False
self.sleeping = False
self.old_brightness = 30
self.add_event('mycroft.awoken', self.handle_awoken)
self.wake_word = Configuration.get()['listener']['wake_word']
self.disabled_confirm_listening = False

@intent_handler(IntentBuilder("NapTimeIntent").require("SleepCommand"))
def handle_go_to_sleep(self, message):
"""
Sends a message to the speech client setting the listener in a
sleep mode.
"""Sends a message to the speech client putting the listener to sleep.
If the user has been told about the waking up process five times
already, it sends a shorter message.
If the user has been told about the waking up process five times
already, it sends a shorter message.
"""
count = self.settings.get('Wake up count', 0)
count += 1
self.settings['Wake up count'] = count

if count <= 5:
self.speak_dialog('going.to.sleep', {'wake_word': self.wake_word})
else:
self.speak_dialog('going.to.sleep.short')

self.bus.emit(Message('recognizer_loop:sleep'))
self.sleeping = True
self.started_by_skill = True
Expand All @@ -62,18 +58,22 @@ def handle_go_to_sleep(self, message):
# Dim and look downward to 'go to sleep'
# TODO: Get current brightness from somewhere
self.old_brightness = 30
for i in range (0, (self.old_brightness - 10) // 2):
for i in range(0, (self.old_brightness - 10) // 2):
self.enclosure.eyes_brightness(self.old_brightness - i * 2)
time.sleep(0.15)
self.enclosure.eyes_look("d")
if self.config_core.get("enclosure").get("platform", "unknown") != "unknown":
platform = self.config_core.get("enclosure").get("platform", "unknown")
if platform != "unknown":
self.bus.emit(Message('mycroft.volume.mute',
data={"speak_message": False}))
data={"speak_message": False}))
elif self.config_core['confirm_listening']:
self.disable_confirm_listening()

def handle_awoken(self, message):
"""
Handler for the mycroft.awoken message (sent when the listener
hears 'Hey Mycroft, Wake Up')
"""Handler for the mycroft.awoken message
The message is sent when the listener hears 'Hey Mycroft, Wake Up',
this handles the user interaction upon wake up.
"""
started_by_skill = self.started_by_skill

Expand All @@ -85,9 +85,9 @@ def handle_awoken(self, message):
wait_while_speaking()

def wake_up_animation(self):
"""
Mild animation to come out of sleep from voice command.
Pop open eyes and wait a sec.
"""Mild animation to come out of sleep from voice command.
Pop open eyes and wait a sec.
"""
self.enclosure.eyes_reset()
time.sleep(1)
Expand All @@ -97,12 +97,31 @@ def wake_up_animation(self):
self.enclosure.eyes_brightness(self.old_brightness)

def awaken(self):
if self.config_core.get("enclosure").get("platform", "unknown") != "unknown":
platform = self.config_core.get("enclosure").get("platform", "unknown")
if platform != "unknown":
self.bus.emit(Message('mycroft.volume.unmute',
data={"speak_message": False}))
elif self.disabled_confirm_listening:
self.enable_confirm_listening()

self.sleeping = False
self.started_by_skill = False

def disable_confirm_listening(self):
msg = Message('configuration.patch',
data={'config': {'confirm_listening': False}}
)
self.bus.emit(msg)
self.disabled_confirm_listening = True
self.log.info('Disabled chirp')

def enable_confirm_listening(self):
msg = Message('configuration.patch',
data={'config': {'confirm_listening': True}}
)
self.bus.emit(msg)
self.disabled_confirm_listening = False
self.log.info('Enabled chirp again')

def create_skill():
return NapTimeSkill()

0 comments on commit 869b316

Please sign in to comment.