-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.go
74 lines (70 loc) · 1.55 KB
/
timer.go
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
package main
import (
log "github.com/sirupsen/logrus"
"time"
)
var ()
func checkTimer(currentTime time.Time) *TimerAction {
for timerName, timerData := range ConfigData.Timers {
log.Debugf("Checking timer %s", timerName)
var alarmTime time.Time
switch timerData.Action {
case FadeUp:
alarmTime = currentTime.Add(time.Duration(ConfigData.FadeUpTime) * time.Minute)
case FadeDown:
alarmTime = currentTime.Add(time.Duration(ConfigData.FadeDownTime) * time.Minute)
default:
alarmTime = currentTime
}
log.Infof("Checking for alarm at time %v so we can start fading", alarmTime)
// Ignore if disabled
if !timerData.Enabled {
continue
}
// Check the day of the week
switch alarmTime.Weekday() {
case time.Sunday:
if !timerData.Sunday {
continue
}
case time.Monday:
if !timerData.Monday {
continue
}
case time.Tuesday:
if !timerData.Tuesday {
continue
}
case time.Wednesday:
if !timerData.Wednesday {
continue
}
case time.Thursday:
if !timerData.Thursday {
continue
}
case time.Friday:
if !timerData.Friday {
continue
}
case time.Saturday:
if !timerData.Saturday {
continue
}
}
log.Debugf("Timer %s matches current day", timerName)
// Check the hour
if alarmTime.Hour() != timerData.Hour {
continue
}
log.Debugf("Timer %s matches current hour", timerName)
// Check the minute
if alarmTime.Minute() != timerData.Minute {
continue
}
// Fire our timer
log.Infof("Timer %s matches", timerName)
return &timerData.Action
}
return nil
}