Skip to content

Commit

Permalink
Log warning if we can not determine a valid interval in the current s…
Browse files Browse the repository at this point in the history
…chedule
  • Loading branch information
stefanwichmann committed Mar 24, 2019
1 parent 15c0782 commit ca11637
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 1 addition & 2 deletions light.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ func (light *Light) updateInterval() {

newInterval, err := light.Schedule.currentInterval(time.Now())
if err != nil {
log.Printf("💡 Light %s - Light has no active interval. Ignoring...", light.Name)
light.Interval = newInterval // Assign empty interval
log.Warningf("💡 Light %s - Could not determine interval for current schedule: %v", light.Name, err)
return
}
if newInterval != light.Interval {
Expand Down
13 changes: 8 additions & 5 deletions schedule.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2018 Stefan Wichmann
// Copyright (c) 2019 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,9 +21,12 @@
// SOFTWARE.
package main

import "time"
import log "github.com/Sirupsen/logrus"
import "errors"
import (
"fmt"
"time"

log "github.com/Sirupsen/logrus"
)

// Schedule represents all relevants timestamps of one day.
// Kelvin will calculate all light states based on the intervals
Expand All @@ -40,7 +43,7 @@ type Schedule struct {
func (schedule *Schedule) currentInterval(timestamp time.Time) (Interval, error) {
// check if timestamp respresents the current day
if timestamp.After(schedule.endOfDay) {
return Interval{TimeStamp{time.Now(), 0, 0}, TimeStamp{time.Now(), 0, 0}}, errors.New("No current interval as the requested timestamp respresents a different day")
return Interval{TimeStamp{time.Now(), 0, 0}, TimeStamp{time.Now(), 0, 0}}, fmt.Errorf("No current interval as the requested timestamp (%v) lays after the end of the current schedule (%v)", timestamp, schedule.endOfDay)
}

// if we are between todays sunrise and sunset, return daylight interval
Expand Down

0 comments on commit ca11637

Please sign in to comment.