Fix usage of maximum backoff intervall (#9652)
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled

This commit is contained in:
andig 2023-08-31 18:39:19 +02:00 • committed by GitHub
parent 4c6105faa7
commit 59fa929362
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 13 deletions

View file

@ -207,7 +207,7 @@ func (c *Easee) chargerSite(charger string) (easee.Site, error) {
// connect creates an HTTP connection to the signalR hub
func (c *Easee) connect(ts oauth2.TokenSource) func() (signalr.Connection, error) {
bo := backoff.NewExponentialBackOff()
bo.MaxElapsedTime = time.Minute
bo.MaxInterval = time.Minute
return func() (conn signalr.Connection, err error) {
defer func() {
@ -447,7 +447,7 @@ func (c *Easee) inExpectedOpMode(enable bool) bool {
c.mux.Lock()
defer c.mux.Unlock()
//start/resume
// start/resume
if enable {
return c.opMode == easee.ModeCharging ||
c.opMode == easee.ModeCompleted ||
@ -455,7 +455,7 @@ func (c *Easee) inExpectedOpMode(enable bool) bool {
c.opMode == easee.ModeReadyToCharge
}
//paused/stopped
// paused/stopped
return c.opMode == easee.ModeAwaitingStart || c.opMode == easee.ModeAwaitingAuthentication
}

View file

@ -119,7 +119,7 @@ func NewSalia(uri string, cache time.Duration) (api.Charger, error) {
func (wb *Salia) heartbeat() {
bo := backoff.NewExponentialBackOff()
bo.InitialInterval = 5 * time.Second
bo.MaxElapsedTime = time.Minute
bo.MaxInterval = time.Minute
for range time.Tick(30 * time.Second) {
if err := backoff.Retry(func() error {

View file

@ -139,9 +139,8 @@ func NewDsmr(uri, energy string, timeout time.Duration) (api.Meter, error) {
// based on https://github.com/basvdlei/gotsmart/blob/master/gotsmart.go
func (m *Dsmr) run(conn net.Conn, done chan struct{}) {
log := util.NewLogger("dsmr")
backoff := backoff.NewExponentialBackOff()
backoff.InitialInterval = time.Second
backoff.MaxInterval = 5 * time.Minute
bo := backoff.NewExponentialBackOff()
bo.MaxInterval = 5 * time.Minute
handle := func(op string, err error) {
log.ERROR.Printf("%s: %v", op, err)
@ -161,7 +160,7 @@ func (m *Dsmr) run(conn net.Conn, done chan struct{}) {
conn, err = m.connect()
if err != nil {
handle("connect", err)
time.Sleep(backoff.NextBackOff().Truncate(time.Second))
time.Sleep(bo.NextBackOff().Truncate(time.Second))
continue
}
@ -169,7 +168,7 @@ func (m *Dsmr) run(conn net.Conn, done chan struct{}) {
}
if b, err := reader.Peek(1); err == nil {
backoff.Reset()
bo.Reset()
if string(b) != "/" {
log.DEBUG.Printf("ignoring garbage character: %c\n", b)
@ -178,7 +177,7 @@ func (m *Dsmr) run(conn net.Conn, done chan struct{}) {
}
} else {
handle("peek", err)
time.Sleep(backoff.NextBackOff().Truncate(time.Second))
time.Sleep(bo.NextBackOff().Truncate(time.Second))
continue
}

View file

@ -83,8 +83,8 @@ func NewRCT(uri, usage string, cache time.Duration, capacity func() float64) (ap
}
bo := backoff.NewExponentialBackOff()
bo.MaxElapsedTime = time.Second
bo.InitialInterval = 10 * time.Millisecond
bo.MaxInterval = time.Second
m := &RCT{
usage: strings.ToLower(usage),

View file

@ -8,7 +8,7 @@ import (
func newBackoff() backoff.BackOff {
bo := backoff.NewExponentialBackOff()
bo.InitialInterval = 5 * time.Second
bo.MaxElapsedTime = time.Minute
bo.InitialInterval = time.Second
bo.MaxInterval = time.Minute
return bo
}