From 9b8f29a6bd4f22c095d5b364da4c8e111da6a755 Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 1 May 2026 13:38:35 +0200 Subject: [PATCH] Ecoflow: use evcc HTTP client for logging (#29530) --- meter/ecoflow.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/meter/ecoflow.go b/meter/ecoflow.go index acc014055..59992009b 100644 --- a/meter/ecoflow.go +++ b/meter/ecoflow.go @@ -8,13 +8,13 @@ import ( "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/util" + "github.com/evcc-io/evcc/util/request" "github.com/spf13/cast" "github.com/tess1o/go-ecoflow" ) // EcoFlow represents the EcoFlow meter type EcoFlow struct { - ctx context.Context usage string serial string cache time.Duration @@ -25,11 +25,11 @@ type EcoFlow struct { } func init() { - registry.AddCtx("ecoflow", NewEcoFlowFromConfig) + registry.Add("ecoflow", NewEcoFlowFromConfig) } // NewEcoFlowFromConfig creates an EcoFlow meter from generic config -func NewEcoFlowFromConfig(ctx context.Context, other map[string]any) (api.Meter, error) { +func NewEcoFlowFromConfig(other map[string]any) (api.Meter, error) { cc := struct { batteryCapacity `mapstructure:",squash"` batteryPowerLimits `mapstructure:",squash"` @@ -70,7 +70,7 @@ func NewEcoFlowFromConfig(ctx context.Context, other map[string]any) (api.Meter, return nil, fmt.Errorf("invalid region: %s", cc.Region) } - m, err := NewEcoFlow(ctx, cc.AccessKey, cc.SecretKey, cc.Serial, cc.Usage, uri, cc.Power, cc.Soc, cc.Cache) + m, err := NewEcoFlow(cc.AccessKey, cc.SecretKey, cc.Serial, cc.Usage, uri, cc.Power, cc.Soc, cc.Cache) if err != nil { return nil, err } @@ -86,14 +86,18 @@ func NewEcoFlowFromConfig(ctx context.Context, other map[string]any) (api.Meter, } // NewEcoFlow constructs the EcoFlow struct -func NewEcoFlow(ctx context.Context, accessKey, secretKey, serial, usage, uri string, +func NewEcoFlow(accessKey, secretKey, serial, usage, uri string, power, soc string, cache time.Duration) (*EcoFlow, error) { + log := util.NewLogger("ecoflow").Redact(accessKey, secretKey, serial) + m := &EcoFlow{ - ctx: ctx, - serial: serial, - usage: usage, - cache: cache, - client: ecoflow.NewEcoflowClient(accessKey, secretKey, ecoflow.WithBaseUrl(uri)), + serial: serial, + usage: usage, + cache: cache, + client: ecoflow.NewEcoflowClient(accessKey, secretKey, + ecoflow.WithBaseUrl(uri), + ecoflow.WithHttpClient(request.NewClient(log)), + ), power: power, batterySoc: soc, } @@ -105,7 +109,7 @@ func NewEcoFlow(ctx context.Context, accessKey, secretKey, serial, usage, uri st // getData retrieves device parameters from EcoFlow API func (m *EcoFlow) getData() (*ecoflow.GetCmdResponse, error) { - ctx, cancel := context.WithTimeout(m.ctx, 30*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() params := []string{m.power}