-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
97 lines (85 loc) · 3.87 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from mycroft import MycroftSkill, intent_file_handler
from mycroft.util import play_wav
import time
from os.path import join, isfile, abspath, dirname
class PomodoroTimer(MycroftSkill):
def __init__(self):
MycroftSkill.__init__(self)
self.session_length = 5 # how many study intervals in session
self.interval_counter = 0 # counts how many study intervals have passed
self.study_duration = 25 # study duration in minutes
self.break_duration = 5 # break duration in minutes
self.break_overflow = False # whether the user takes a too-long break
self.sound_file = join(abspath(dirname(__file__)), 'time-is-now.mp3')
self.is_running = False
# 1. The start: the user tells Mycroft to start a new pomodoro session
@intent_file_handler('session.start.intent')
def handle_session_start(self, message):
# 2. Start a new study timer and speak confirmation
if self.is_running:
self.speak_dialog('session.already.running')
else:
self.is_running = True
self.speak_dialog('session.start')
self.start_study_timer()
def start_study_timer(self):
# 3. Sleep for the length of the study interval
time.sleep(60 * self.study_duration)
# 4. Check if end of session
self.interval_counter += 1
play_wav(self.sound_file)
time.sleep(3)
if self.interval_counter <= self.session_length:
self.end_session() # if yes, end the session
else:
self.take_break() # if not, take a break
def take_break(self):
# 5. Communicate start of break
self.speak_dialog('break.start')
time.sleep(60 * self.break_duration) # sleep for duration of break
play_wav(self.sound_file)
time.sleep(3)
self.speak_dialog('break.end') # communicate end of break
self.start_study_timer() # start studying again (go back to 3.)
def end_session(self):
self.is_running = False
self.speak_dialog('session.end')
@intent_file_handler('session.end.enforce.intent')
def handle_session_end(self, message):
if self.is_running:
self.is_running = False
self.speak_dialog('session.end.enforce')
else:
self.speak_dialog('session.not.running')
@intent_file_handler('session.left.info.intent')
def handle_intervals_left_info(self, message):
# Check if there is even a session running, else it doesn't make sense
# to speak information about it.
if self.is_running:
amount = self.session_length - self.interval_counter
self.speak_dialog('session.left.info', {'amount':amount})
else:
self.speak_dialog('session.not.running')
def stop(self):
self.is_running = False
@intent_file_handler('config.set.intent')
def handle_config_set(self, message):
config_type = message.data.get('type')
duration = message.data.get('duration')
self.log.error('The function handle_config_set is not yet implemented.')
#if config_type is 'study':
# self.settings['{}_duration'.format(config_type)] = duration
#elif config_type is 'break':
# self.settings['{}_duration'.format(config_type)] = duration
self.speak_dialog('config.set.success',
{'type' : config_type, 'duration' : duration})
@intent_file_handler('config.get.intent')
def handle_config_get(self, message):
config_type = message.data.get('Options')
self.log.error('The function handle_config_get is not yet implemented.')
#formatted_config_type = '{}_duration'.format(config_type)
#duration = self.settings.get(formatted_config_type)
#self.speak_dialog('config.get',
# { 'type' : config_type, 'duration' : duration})
def create_skill():
return PomodoroTimer()