Start routine at wakeup end
This commit is contained in:
parent
1def1ff67a
commit
e1f5fbcd6c
7 changed files with 101 additions and 16 deletions
|
|
@ -40,37 +40,57 @@ func (h *Hour) UnmarshalJSON(src []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func GetNextAlarm(cfg *config.Config, db *LevelDBStorage) (*time.Time, error) {
|
||||
func GetNextAlarm(cfg *config.Config, db *LevelDBStorage) (*time.Time, []Identifier, error) {
|
||||
alarmsRepeated, err := GetAlarmsRepeated(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var closestAlarm *time.Time
|
||||
var closestAlarmRoutines []Identifier
|
||||
for _, alarm := range alarmsRepeated {
|
||||
next := alarm.GetNextOccurence(cfg, db)
|
||||
if next != nil && (closestAlarm == nil || closestAlarm.After(*next)) {
|
||||
closestAlarm = next
|
||||
closestAlarmRoutines = alarm.FollowingRoutines
|
||||
}
|
||||
}
|
||||
|
||||
alarmsSingle, err := GetAlarmsSingle(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
for _, alarm := range alarmsSingle {
|
||||
if closestAlarm == nil || (closestAlarm.After(alarm.Time) && alarm.Time.After(now)) {
|
||||
closestAlarm = &alarm.Time
|
||||
closestAlarmRoutines = alarm.FollowingRoutines
|
||||
}
|
||||
}
|
||||
|
||||
return closestAlarm, nil
|
||||
return closestAlarm, closestAlarmRoutines, nil
|
||||
}
|
||||
|
||||
func GetNextException(cfg *config.Config, db *LevelDBStorage) (*time.Time, error) {
|
||||
alarmsExceptions, err := GetAlarmExceptions(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var closestException *time.Time
|
||||
for _, except := range alarmsExceptions {
|
||||
if except != nil && time.Time(*except.End).After(time.Now()) && (closestException == nil || closestException.After(time.Time(*except.Start))) {
|
||||
tmp := time.Time(*except.Start)
|
||||
closestException = &tmp
|
||||
}
|
||||
}
|
||||
|
||||
return closestException, nil
|
||||
}
|
||||
|
||||
func DropNextAlarm(cfg *config.Config, db *LevelDBStorage) error {
|
||||
timenext, err := GetNextAlarm(cfg, db)
|
||||
timenext, _, err := GetNextAlarm(cfg, db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue