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

Event handling for active alarms #121

Merged
merged 6 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.pyc
settings.json
mycroft
mycroft

# Pycharm project files
.idea/
19 changes: 18 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,28 @@ def initialize(self):

self._schedule()

# Support query for active alarms from other skills
# TODO: remove the "private.mycroftai.has_alarm" event in favor of the
# "skill.alarm.query-active" event.
self.add_event("private.mycroftai.has_alarm", self.on_has_alarm)
self.add_event("skill.alarm.query-active", self.handle_active_alarm_query)

# TODO: remove the "private.mycroftai.has_alarm" event in favor of the
# "skill.alarm.query-active" event.
def on_has_alarm(self, message):
"""Reply to requests for alarm on/off status."""
total = len(self.settings["alarm"])
self.bus.emit(message.response(data={"active_alarms": total}))

def handle_active_alarm_query(self, message):
"""Emits an event indicating whether or not there are any active alarms.

In this case, an "active alarm" is defined as any alarms that exist for a time
in the future.
"""
event_data = {"active_alarms": bool(self.settings["alarm"])}
event = message.response(data=event_data)
self.bus.emit(event)

def set_alarm(self, when, name=None, repeat=None):
"""Set an alarm at the specified datetime."""
requested_time = when.replace(second=0, microsecond=0)
Expand Down Expand Up @@ -206,6 +220,9 @@ def _schedule(self):
self.schedule_event(
self._alarm_expired, to_system(alarm_dt), name="NextAlarm"
)
event_data = {"active_alarms": bool(self.settings["alarm"])}
event = Message("skill.alarm.scheduled", data=event_data)
self.bus.emit(event)

def _get_recurrence(self, utterance: str):
"""Get recurrence pattern from user utterance."""
Expand Down