add state restore after Nanoleaf controller reboots.

This commit is contained in:
2021-05-24 08:30:32 +02:00
parent d6fdb48023
commit 954d6bd3e1
2 changed files with 16 additions and 1 deletions
+15 -1
View File
@@ -207,15 +207,29 @@ func (b *bridge) Run(ctx context.Context, info models.Bridge, ch chan<- models.E
go func() {
ticker := time.NewTicker(time.Second * 5)
hadErrors := false
for {
select {
case <-ticker.C:
case <-ctx2.Done():
}
err := b.updateEffect(ctx)
reqTimeout, cancel := context.WithTimeout(ctx2, time.Second*4)
err := b.updateEffect(reqTimeout)
cancel()
if err != nil {
log.Println("Failed to update effects:", err, "This error is non-fatal, and it will be retried shortly.")
hadErrors = true
} else if hadErrors {
b.mu.Lock()
for _, panel := range b.panels {
panel.Stale = true
panel.SlowUpdates = 3
panel.TicksUntilSlowUpdate = 10
}
b.mu.Unlock()
hadErrors = false
}
}
}()