From 55a1efd695b973b2beeefb03a4841969cf3a243a Mon Sep 17 00:00:00 2001 From: Thomas Speer Date: Tue, 7 Oct 2025 08:33:51 +0200 Subject: [PATCH] Hardybarth Salia: add optional user/password (#24161) --- charger/hardybarth-salia.go | 18 +++++++++++++----- .../definition/charger/hardybarth-salia.yaml | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/charger/hardybarth-salia.go b/charger/hardybarth-salia.go index 93d8872a1..bf551a130 100644 --- a/charger/hardybarth-salia.go +++ b/charger/hardybarth-salia.go @@ -33,6 +33,7 @@ import ( "github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/sponsor" + "github.com/evcc-io/evcc/util/transport" "github.com/hashicorp/go-version" ) @@ -57,8 +58,10 @@ func init() { // NewSaliaFromConfig creates a Salia cPH2 charger from generic config func NewSaliaFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { cc := struct { - URI string - Cache time.Duration + URI string + User string + Password string + Cache time.Duration }{ Cache: time.Second, } @@ -67,12 +70,13 @@ func NewSaliaFromConfig(ctx context.Context, other map[string]interface{}) (api. return nil, err } - return NewSalia(ctx, cc.URI, cc.Cache) + return NewSalia(ctx, cc.URI, cc.User, cc.Password, cc.Cache) } // NewSalia creates Hardy Barth charger with Salia controller -func NewSalia(ctx context.Context, uri string, cache time.Duration) (api.Charger, error) { - log := util.NewLogger("salia") +func NewSalia(ctx context.Context, uri, user, password string, cache time.Duration) (api.Charger, error) { + basicAuth := transport.BasicAuthHeader(user, password) + log := util.NewLogger("salia").Redact(user, password, basicAuth) uri = strings.TrimSuffix(uri, "/") + "/api" @@ -83,6 +87,10 @@ func NewSalia(ctx context.Context, uri string, cache time.Duration) (api.Charger current: 6, } + if user != "" && password != "" { + wb.Client.Transport = transport.BasicAuth(user, password, wb.Client.Transport) + } + wb.apiG = util.ResettableCached(func() (salia.Api, error) { var res salia.Api err := wb.GetJSON(wb.uri, &res) diff --git a/templates/definition/charger/hardybarth-salia.yaml b/templates/definition/charger/hardybarth-salia.yaml index a325ee701..853954491 100644 --- a/templates/definition/charger/hardybarth-salia.yaml +++ b/templates/definition/charger/hardybarth-salia.yaml @@ -14,8 +14,27 @@ products: generic: cPμ2 requirements: evcc: ["sponsorship"] + description: + de: >- + Wenn du ohne Benutzername und Passwort die Meldung '401 (Unauthorized)' bekommst, + benutze die Benutzernamen und Passwort Kombination, die du vom Installateur deiner Wallbox bekommen hast, + die auch für die Weboberfläche der Wallbox funktioniert. + en: >- + If you get the message '401 (Unauthorized)' without a username and password, + use the username and password that you received from the installer of your wallbox. + The combo that also works for the web interface of the wallbox. params: - name: host + - name: user + help: + de: Benutzername (optional, nur bei aktivierter Basic Auth der Wallbox) + en: Username (optional, only if Basic Auth is enabled on the wallbox) + - name: password + help: + de: Passwort (optional, nur bei aktivierter Basic Auth der Wallbox) + en: Password (optional, only if Basic Auth is enabled on the wallbox) render: | type: hardybarth-salia uri: http://{{ .host }} + user: {{ .user }} + password: {{ .password }}