From: jweigele Date: Thu, 2 Feb 2023 21:20:42 +0000 (-0800) Subject: Force update of lights when overriding color X-Git-Url: http://git.hexthepla.net/?a=commitdiff_plain;h=537addca869ad4559cbe5c2b23c346d0261db2c7;p=rabbit_go Force update of lights when overriding color --- diff --git a/lights/main.go b/lights/main.go index b0d2a63..a6fd6ec 100644 --- a/lights/main.go +++ b/lights/main.go @@ -96,6 +96,7 @@ func (curSwitch *Switch) setState(state bool) { 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) } @@ -279,6 +280,12 @@ func (relay *RGBRelay) LastUpdateTooOld() bool { 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