Skip to content

Commit

Permalink
Fix usage of maximum backoff intervall (evcc-io#9652)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Aug 31, 2023
1 parent 4c6105f commit 59fa929
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions charger/easee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -447,15 +447,15 @@ 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 ||
c.opMode == easee.ModeAwaitingStart ||
c.opMode == easee.ModeReadyToCharge
}

//paused/stopped
// paused/stopped
return c.opMode == easee.ModeAwaitingStart || c.opMode == easee.ModeAwaitingAuthentication
}

Expand Down
2 changes: 1 addition & 1 deletion charger/hardybarth-salia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 5 additions & 6 deletions meter/dsmr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -161,15 +160,15 @@ 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
}

reader.Reset(conn)
}

if b, err := reader.Peek(1); err == nil {
backoff.Reset()
bo.Reset()

if string(b) != "/" {
log.DEBUG.Printf("ignoring garbage character: %c\n", b)
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion meter/rct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions tariff/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 59fa929

Please sign in to comment.