|
@ -35,8 +35,8 @@ func StartEventHandler() { |
|
|
for range time.NewTicker(time.Minute).C { |
|
|
for range time.NewTicker(time.Minute).C { |
|
|
config.EventChannel <- models.Event{Name: "TimeChanged", Payload: map[string]string{ |
|
|
config.EventChannel <- models.Event{Name: "TimeChanged", Payload: map[string]string{ |
|
|
"weekdayName": time.Now().In(loc).Format("Monday"), |
|
|
"weekdayName": time.Now().In(loc).Format("Monday"), |
|
|
"month": time.Now().In(loc).Format("01"), |
|
|
|
|
|
"year": time.Now().In(loc).Format("2006"), |
|
|
|
|
|
|
|
|
"month": time.Now().In(loc).Format("01"), |
|
|
|
|
|
"year": time.Now().In(loc).Format("2006"), |
|
|
}} |
|
|
}} |
|
|
} |
|
|
} |
|
|
}() |
|
|
}() |
|
@ -49,7 +49,7 @@ func handleEvent(event models.Event) (responses []models.Event) { |
|
|
startTime := time.Now() |
|
|
startTime := time.Now() |
|
|
defer func() { |
|
|
defer func() { |
|
|
duration := time.Since(startTime) |
|
|
duration := time.Since(startTime) |
|
|
if duration > time.Millisecond * 250 { |
|
|
|
|
|
|
|
|
if duration > time.Millisecond*250 { |
|
|
log.Println(event.Name, "took long to handle:", duration) |
|
|
log.Println(event.Name, "took long to handle:", duration) |
|
|
} |
|
|
} |
|
|
}() |
|
|
}() |
|
@ -134,7 +134,7 @@ func handleEvent(event models.Event) (responses []models.Event) { |
|
|
if action.SetIntensity != nil { |
|
|
if action.SetIntensity != nil { |
|
|
newState.Intensity = action.SetIntensity |
|
|
newState.Intensity = action.SetIntensity |
|
|
} else if action.AddIntensity != nil { |
|
|
} else if action.AddIntensity != nil { |
|
|
newIntensity := math.Max(0, math.Min(1, device.State.Intensity + *action.AddIntensity)) |
|
|
|
|
|
|
|
|
newIntensity := math.Max(0, math.Min(1, device.State.Intensity+*action.AddIntensity)) |
|
|
newState.Intensity = &newIntensity |
|
|
newState.Intensity = &newIntensity |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|