func (curSwitch *Switch) setColor() {
curTime := time.Now().UTC()
curSwitch.ColorStateExpiresAt = curTime.Add(time.Duration(curSwitch.OverrideSeconds) * time.Second)
+ curSwitch.parentRelay.ForceRefresh()
logger.Info("Setting color state for switch", "switch", curSwitch)
}
return false
}
+// create a situation where next check for dimming will think we've been idle and need to refresh state
+func (relay *RGBRelay) ForceRefresh() {
+ staleDuration := time.Duration(relay.UpdateStaleness) * time.Second
+ relay.LastUpdate = relay.LastUpdate.Add(-staleDuration)
+}
+
func (relay *RGBRelay) shouldDim() bool {
curTime := time.Now().UTC()
dimmingDuration := time.Duration(relay.DimmingTimeout) * time.Second