Force update of lights when overriding color
authorjweigele <jweigele@local>
Thu, 2 Feb 2023 21:20:42 +0000 (13:20 -0800)
committerjweigele <jweigele@local>
Thu, 2 Feb 2023 21:20:42 +0000 (13:20 -0800)
lights/main.go

index b0d2a63509b1d1e39b5257295ae9000fa8ff0002..a6fd6ecc5bb152c4d0713796463abfa19ff1a8bf 100644 (file)
@@ -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