From 537addca869ad4559cbe5c2b23c346d0261db2c7 Mon Sep 17 00:00:00 2001 From: jweigele Date: Thu, 2 Feb 2023 13:20:42 -0800 Subject: [PATCH] Force update of lights when overriding color --- lights/main.go | 7 +++++++ 1 file changed, 7 insertions(+) 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 -- 2.30.2