From 954d6bd3e1445f18ec3fd57cf510bcd3cb30fbd0 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Mon, 24 May 2021 08:30:32 +0200 Subject: [PATCH] add state restore after Nanoleaf controller reboots. --- internal/drivers/nanoleaf/bridge.go | 16 +++++++++++++++- models/errors.go | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/drivers/nanoleaf/bridge.go b/internal/drivers/nanoleaf/bridge.go index 088557a..2962114 100644 --- a/internal/drivers/nanoleaf/bridge.go +++ b/internal/drivers/nanoleaf/bridge.go @@ -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 } } }() diff --git a/models/errors.go b/models/errors.go index 69ab456..78d8dc4 100644 --- a/models/errors.go +++ b/models/errors.go @@ -13,3 +13,4 @@ var ErrMissingToken = errors.New("driver is missing authentication information") var ErrIncorrectToken = errors.New("driver is not accepting authentication information") var ErrUnexpectedResponse = errors.New("driver api returned unexpected response (wrong driver selected?)") var ErrBridgeSearchFailed = errors.New("bridge search failed") +var ErrAddressOnlyDryRunnable = errors.New("this address may only be used for a dry run")