-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 485e54c
Showing
25 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# Copyright 2016 Mycroft AI, Inc. | ||
# | ||
# This file is part of Mycroft Core. | ||
# | ||
# Mycroft Core is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Mycroft Core is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
|
||
import time | ||
from alsaaudio import Mixer | ||
from datetime import datetime, timedelta | ||
|
||
import yaml | ||
from adapt.intent import IntentBuilder | ||
from os.path import dirname, join | ||
|
||
from mycroft.skills.scheduled_skills import ScheduledCRUDSkill | ||
from mycroft.util import play_mp3 | ||
|
||
__author__ = 'jdorleans' | ||
|
||
|
||
# TODO - Localization | ||
class AlarmSkill(ScheduledCRUDSkill): | ||
def __init__(self): | ||
super(AlarmSkill, self).__init__("AlarmSkill", None) | ||
self.alarm_on = False | ||
self.max_delay = self.config.get('max_delay') | ||
self.repeat_time = self.config.get('repeat_time') | ||
self.extended_delay = self.config.get('extended_delay') | ||
self.file_path = join(dirname(__file__), self.config.get('filename')) | ||
|
||
def initialize(self): | ||
super(AlarmSkill, self).initialize() | ||
intent = IntentBuilder( | ||
'AlarmSkillStopIntent').require('AlarmSkillStopVerb') \ | ||
.require('AlarmSkillKeyword').build() | ||
self.register_intent(intent, self.__handle_stop) | ||
|
||
def load_data(self): | ||
try: | ||
with self.file_system.open(self.PENDING_TASK, 'r') as f: | ||
self.data = yaml.safe_load(f) | ||
assert self.data | ||
except: | ||
self.data = {} | ||
|
||
def load_repeat_data(self): | ||
try: | ||
with self.file_system.open(self.REPEAT_TASK, 'r') as f: | ||
self.repeat_data = yaml.safe_load(f) | ||
assert self.repeat_data | ||
except: | ||
self.repeat_data = {} | ||
|
||
def __handle_stop(self, message): | ||
if self.alarm_on: | ||
self.speak_dialog('alarm.off') | ||
self.alarm_on = False | ||
|
||
def notify(self, timestamp): | ||
with self.LOCK: | ||
if self.data.__contains__(timestamp): | ||
volume = None | ||
self.alarm_on = True | ||
delay = self.__calculate_delay(self.max_delay) | ||
|
||
while self.alarm_on and datetime.now() < delay: | ||
play_mp3(self.file_path).communicate() | ||
self.speak_dialog('alarm.stop') | ||
time.sleep(self.repeat_time + 2) | ||
if not volume and datetime.now() >= delay: | ||
mixer = Mixer() | ||
volume = mixer.getvolume()[0] | ||
mixer.setvolume(100) | ||
delay = self.__calculate_delay(self.extended_delay) | ||
if volume: | ||
Mixer().setvolume(volume) | ||
self.remove(timestamp) | ||
self.alarm_on = False | ||
self.save() | ||
|
||
@staticmethod | ||
def __calculate_delay(seconds): | ||
return datetime.now() + timedelta(seconds=seconds) | ||
|
||
def save(self): | ||
with self.file_system.open(self.PENDING_TASK, 'w') as f: | ||
yaml.safe_dump(self.data, f) | ||
with self.file_system.open(self.REPEAT_TASK, 'w') as f: | ||
yaml.safe_dump(self.repeat_data, f) | ||
if not self.alarm_on: | ||
self.schedule() | ||
|
||
def stop(self): | ||
self.__handle_stop(None) | ||
|
||
|
||
def create_skill(): | ||
return AlarmSkill() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
the alarm has been turned off | ||
the alarm has been shut off | ||
the alarm has been stopped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Say, turn off alarm to end this alarm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Alarm set for {{datetime}} | ||
You have a new alarm on {{datetime}} | ||
A new alarm for {{datetime}} was added |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Sorry, I didn't find a valid date and time to alarm you. | ||
It was not possible to set an alarm for the informed date and time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
There is no alarm to be removed | ||
You don't have any alarm to be deleted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{amount}} alarms removed | ||
{{amount}} alarms were cancelled | ||
You have deleted {{amount}} alarms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
One alarm removed | ||
An alarm was cancelled | ||
You have deleted one alarm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
You have an alarm on {{datetime}} | ||
There is an alarm set for {{datetime}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
There is no alarm to be listed | ||
You don't have any alarm to be listed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"utterance": "alarm in 2 months", | ||
"intent_type": "AlarmSkillCreateIntent", | ||
"intent": { | ||
"AlarmSkillCreateVerb": "alarm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"utterance": "alarm on july 4th 2016 at 3pm", | ||
"intent_type": "AlarmSkillCreateIntent", | ||
"intent": { | ||
"AlarmSkillCreateVerb": "alarm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"utterance": "set a timer for tomorrow evening", | ||
"intent_type": "AlarmSkillCreateIntent", | ||
"intent": { | ||
"AlarmSkillCreateVerb": "timer" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"utterance": "set an alarm to next saturday", | ||
"intent_type": "AlarmSkillCreateIntent", | ||
"intent": { | ||
"AlarmSkillCreateVerb": "alarm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"utterance": "list two alarms", | ||
"intent_type": "AlarmSkillListIntent", | ||
"intent": { | ||
"AlarmSkillListVerb": "list", | ||
"AlarmSkillAmount": "2", | ||
"AlarmSkillKeyword": "alarms" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"utterance": "show all my timers", | ||
"intent_type": "AlarmSkillListIntent", | ||
"intent": { | ||
"AlarmSkillListVerb": "show", | ||
"AlarmSkillAmount": "all", | ||
"AlarmSkillKeyword": "timers" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"utterance": "cancel one alarm", | ||
"intent_type": "AlarmSkillDeleteIntent", | ||
"intent": { | ||
"AlarmSkillDeleteVerb": "cancel", | ||
"AlarmSkillAmount": "1", | ||
"AlarmSkillKeyword": "alarm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"utterance": "erase the next alarm", | ||
"intent_type": "AlarmSkillDeleteIntent", | ||
"intent": { | ||
"AlarmSkillDeleteVerb": "erase", | ||
"AlarmSkillAmount": "the next", | ||
"AlarmSkillKeyword": "alarm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
all|all my | ||
1|one | ||
2|two | ||
the next | ||
the following |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
timer | ||
timers | ||
alarm | ||
alarms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
erase | ||
cancel | ||
delete | ||
remove |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
timer | ||
timers | ||
alarm | ||
alarms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
show | ||
list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
off | ||
end | ||
stop |