Browse Source

add state restore after Nanoleaf controller reboots.

pull/1/head
Gisle Aune 4 years ago
parent
commit
954d6bd3e1
  1. 16
      internal/drivers/nanoleaf/bridge.go
  2. 1
      models/errors.go

16
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() { go func() {
ticker := time.NewTicker(time.Second * 5) ticker := time.NewTicker(time.Second * 5)
hadErrors := false
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
case <-ctx2.Done(): case <-ctx2.Done():
} }
err := b.updateEffect(ctx)
reqTimeout, cancel := context.WithTimeout(ctx2, time.Second*4)
err := b.updateEffect(reqTimeout)
cancel()
if err != nil { if err != nil {
log.Println("Failed to update effects:", err, "This error is non-fatal, and it will be retried shortly.") 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
} }
} }
}() }()

1
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 ErrIncorrectToken = errors.New("driver is not accepting authentication information")
var ErrUnexpectedResponse = errors.New("driver api returned unexpected response (wrong driver selected?)") var ErrUnexpectedResponse = errors.New("driver api returned unexpected response (wrong driver selected?)")
var ErrBridgeSearchFailed = errors.New("bridge search failed") var ErrBridgeSearchFailed = errors.New("bridge search failed")
var ErrAddressOnlyDryRunnable = errors.New("this address may only be used for a dry run")
Loading…
Cancel
Save