Skip to content

Commit 1a0d7a1

Browse files
committed
Improve timer setting resilience.
Secretly tolerate timers set in minutes or hours as well as seconds. Signed-off-by: Katharine Berry <[email protected]>
1 parent 61c7765 commit 1a0d7a1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

service/assistant/functions/alarms.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type AlarmInput struct {
3535
type TimerInput struct {
3636
// If setting a timer, the number of seconds to set the timer for. Required for timers.
3737
Duration int `json:"duration_seconds"`
38+
// These aren't exposed, but sometimes the model decides to use them anyway.
39+
DurationMinutes int `json:"duration_minutes"`
40+
DurationHours int `json:"duration_hours"`
3841
// An optional name for the alarm or timer.
3942
Name string `json:"name"`
4043
}
@@ -234,8 +237,12 @@ func timerImpl(ctx context.Context, quotaTracker *quota.Tracker, args interface{
234237
}
235238
input := args.(*TimerInput)
236239
log.Println("Asking watch to set an alarm...")
240+
duration := input.Duration + input.DurationMinutes*60 + input.DurationHours*3600
241+
if duration == 0 {
242+
return Error{Error: "You need to pass the timer duration in seconds to duration_seconds (e.g. duration_seconds=300 for a 5 minute timer)."}
243+
}
237244
requests <- map[string]interface{}{
238-
"duration": input.Duration,
245+
"duration": duration,
239246
"isTimer": true,
240247
"name": input.Name,
241248
"action": "set_alarm",

0 commit comments

Comments
 (0)