From 1e509e4f6ed66ecec11f1f9f2f0d1de12f95d4a9 Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 24 Feb 2026 11:40:52 +0100 Subject: [PATCH] Simplify --- charger/warp-ws.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/charger/warp-ws.go b/charger/warp-ws.go index 10bc9449a..475920845 100644 --- a/charger/warp-ws.go +++ b/charger/warp-ws.go @@ -182,17 +182,18 @@ func NewWarpWS(ctx context.Context, uri, user, password string, meterIndex uint) } } - go w.run(uri, user, password, ctx) + go w.run(ctx, uri, user, password) return w, nil } -func (w *WarpWS) run(uri, user, pass string, ctx context.Context) { - bo := backoff.NewExponentialBackOff(backoff.WithMaxElapsedTime(0)) - bo.MaxInterval = 30 * time.Second +func (w *WarpWS) run(ctx context.Context, uri, user, pass string) { + bo := backoff.NewExponentialBackOff( + backoff.WithMaxInterval(30*time.Second), + backoff.WithMaxElapsedTime(0)) for ctx.Err() == nil { - w.log.DEBUG.Printf("ws connecting to %s …", uri) + w.log.DEBUG.Printf("ws connecting to %s", uri) conn, resp, err := dialWebsocket(ctx, uri, user, pass) if err != nil { @@ -212,16 +213,10 @@ func (w *WarpWS) run(uri, user, pass string, ctx context.Context) { } } - if ctx.Err() != nil { - return - } - d := bo.NextBackOff() - w.log.DEBUG.Printf("ws reconnecting to %s in %v", uri, d) - select { case <-ctx.Done(): return - case <-time.After(d): + case <-time.After(bo.NextBackOff()): } } }