Skip to content

Commit

Permalink
streamline event types (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
emphasize authored Dec 26, 2023
1 parent b6c2bb1 commit a88f971
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
65 changes: 39 additions & 26 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,22 @@ def initialize(self):
else:
self.add_event("mycroft.ready", self.on_ready, once=True)

self.add_event("ovos.get_alerts", self._distribute_alerts)
self.add_event("alerts.gui.dismiss_notification",
self.add_event("ovos.alerts.get_alerts", self._event_get_alerts)
self.add_event("ovos.alerts.dismiss_notification",
self._gui_dismiss_notification)
self.add_event("ovos.gui.show.active.timers", self._on_display_gui)
self.add_event("ovos.gui.show.active.alarms", self._on_display_gui)

self.gui.register_handler("timerskill.gui.stop.timer",
self.gui.register_handler("ovos.alerts.cancel_timer",
self._gui_cancel_timer)
self.gui.register_handler("ovos.alarm.skill.cancel",
self._gui_cancel_alarm)
self.gui.register_handler("ovos.alarm.skill.snooze",
self._gui_snooze_alarm)
self.gui.register_handler("ovos.alerts.cancel_alarm",
self._event_cancel_alarm)
self.add_event("ovos.alerts.cancel_alarm",
self._event_cancel_alarm)
self.gui.register_handler("ovos.alerts.snooze_alarm",
self._event_snooze_alarm)
self.add_event("ovos.alerts.snooze_alarm",
self._event_snooze_alarm)

def on_ready(self, _: Message):
"""
Expand Down Expand Up @@ -1410,7 +1414,7 @@ def _pick_one_by_time(self, alerts: List[Alert], dialog: str = ""):
return alerts[0]

# Static parser methods
def _distribute_alerts(self, message):
def _event_get_alerts(self, message):
"""
Handles a request to get scheduled events for a specified
user and disposition.
Expand Down Expand Up @@ -1606,7 +1610,7 @@ def _create_homescreen_notification(self, alert: Alert, duration: int = 0):
LOG.debug(f'add notification: {spoken_type}: {alert.alert_name}')
self.gui.show_notification(content=f'{spoken_type}: {alert.alert_name}',
duration=duration,
action='alerts.gui.dismiss_notification',
action='ovos.alerts.dismiss_notification',
noticetype=noticetype,
callback_data={'alert': alert.data})

Expand Down Expand Up @@ -1661,12 +1665,17 @@ def _gui_cancel_timer(self, message: Message):
LOG.debug(("Timers still active on GUI: "
f"{self.alert_manager.active_gui_timers}"))

def _gui_cancel_alarm(self, message: Message):
def _event_cancel_alarm(self, message: Message):
"""
Handle a gui alarm dismissal
Handle a alarm dismissal per event
"""
alert_id = message.data.get('alarmIndex')
self._dismiss_alert(alert_id, speak=True)
alert_ids = message.data.get('alarmIndex')
if alert_ids is None:
self.alert_manager.get_active_alerts(alert_type=AlertType.ALARM)
elif isinstance(alert_ids, str):
alert_ids = [alert_ids]
for alert_id in alert_ids:
self._dismiss_alert(alert_id, speak=True)

def _release_gui_alarm(self, alert_id: str):
alarm = self.alert_manager.get_alert(alert_id)
Expand All @@ -1690,19 +1699,23 @@ def _release_gui_alarm(self, alert_id: str):
if alarm.ocp_request:
self.bus.emit(Message("system.display.homescreen", {}))

def _gui_snooze_alarm(self, message):
"""
Handle a gui alarm snooze request
"""
alert_id = message.data.get('alarmIndex')
LOG.info(f"GUI Snooze alert: {alert_id}")
alert = self.alert_manager.get_alert(alert_id)

self._snooze_alert(alert)
self.speak_dialog("confirm_snooze_alert",
{"name": alert.alert_name,
"duration": nice_duration(
self.snooze_duration)})
def _event_snooze_alarm(self, message):
"""
Handle a alarm snooze per event
"""
alert_ids = message.data.get('alarmIndex')
if alert_ids is None:
self.alert_manager.get_active_alerts(alert_type=AlertType.ALARM)
elif isinstance(alert_ids, str):
alert_ids = [alert_ids]
for alert_id in alert_ids:
alert = self.alert_manager.get_alert(alert_id)
LOG.info(f"GUI Snooze alert: {alert_id}")
self._snooze_alert(alert)
self.speak_dialog("confirm_snooze_alert",
{"name": alert.alert_name,
"duration": nice_duration(
self.snooze_duration)}, wait=True)

def _gui_dismiss_notification(self, message):
if not message.data.get('alert'):
Expand Down
2 changes: 1 addition & 1 deletion ui/+mediacenter/TimerCard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ItemDelegate {
if (timerViews.count == 1) {
Mycroft.MycroftController.sendText("cancel all timers")
}
triggerGuiEvent("timerskill.gui.stop.timer", {"timer": modelData})
triggerGuiEvent("ovos.alerts.cancel_timer", {"timer": modelData})
}

background: Rectangle {
Expand Down
4 changes: 2 additions & 2 deletions ui/AlarmButtonView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Rectangle {
}
onClicked: {
Mycroft.SoundEffects.playClickedSound(Qt.resolvedUrl("sounds/clicked.wav"))
triggerGuiEvent("ovos.alarm.skill.snooze", {"alarmIndex": alarmIndex, "alarmContext": alarmContext, "alarmName": alarmName})
triggerGuiEvent("ovos.alerts.snooze_alarm", {"alarmIndex": alarmIndex, "alarmContext": alarmContext, "alarmName": alarmName})
}

onPressed: {
Expand Down Expand Up @@ -121,7 +121,7 @@ Rectangle {
}
onClicked: {
Mycroft.SoundEffects.playClickedSound(Qt.resolvedUrl("sounds/clicked.wav"))
triggerGuiEvent("ovos.alarm.skill.cancel", {"alarmIndex": alarmIndex, "alarmContext": alarmContext, "alarmName": alarmName})
triggerGuiEvent("ovos.alerts.cancel_alarm", {"alarmIndex": alarmIndex, "alarmContext": alarmContext, "alarmName": alarmName})
}

onPressed: {
Expand Down
2 changes: 1 addition & 1 deletion ui/TimerCard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ ItemDelegate {
}

onClicked: {
triggerGuiEvent("timerskill.gui.stop.timer", {"timer": modelData})
triggerGuiEvent("ovos.alerts.cancel_timer", {"timer": modelData})
}
}
}
Expand Down

0 comments on commit a88f971

Please sign in to comment.