diff --git a/meter/zendure.go b/meter/zendure.go index e3fb541b25..fd7476effd 100644 --- a/meter/zendure.go +++ b/meter/zendure.go @@ -2,6 +2,7 @@ package meter import ( "fmt" + "strings" "time" "github.com/evcc-io/evcc/api" @@ -21,9 +22,10 @@ type Zendure struct { // NewZendureFromConfig creates a Zendure meter from generic config func NewZendureFromConfig(other map[string]interface{}) (api.Meter, error) { cc := struct { - Usage, Account, Serial string - Timeout time.Duration + Usage, Account, Serial, Region string + Timeout time.Duration }{ + Region: "EU", Timeout: 30 * time.Second, } @@ -31,7 +33,8 @@ func NewZendureFromConfig(other map[string]interface{}) (api.Meter, error) { return nil, err } - conn, err := zendure.NewConnection(cc.Account, cc.Serial, cc.Timeout) + global := strings.ToUpper(cc.Region) != "EU" + conn, err := zendure.NewConnection(cc.Account, cc.Serial, global, cc.Timeout) if err != nil { return nil, err } diff --git a/meter/zendure/connection.go b/meter/zendure/connection.go index 758d4ad83a..47c447a080 100644 --- a/meter/zendure/connection.go +++ b/meter/zendure/connection.go @@ -22,7 +22,7 @@ type Connection struct { data *util.Monitor[Data] } -func NewConnection(account, serial string, timeout time.Duration) (*Connection, error) { +func NewConnection(account, serial string, global bool, timeout time.Duration) (*Connection, error) { mu.Lock() defer mu.Unlock() @@ -31,7 +31,7 @@ func NewConnection(account, serial string, timeout time.Duration) (*Connection, return conn, nil } - res, err := MqttCredentials(account, serial) + res, err := MqttCredentials(account, serial, global) if err != nil { return nil, err } diff --git a/meter/zendure/credentials.go b/meter/zendure/credentials.go index a64bdccd5d..5c1ff21dd0 100644 --- a/meter/zendure/credentials.go +++ b/meter/zendure/credentials.go @@ -8,9 +8,12 @@ import ( "github.com/evcc-io/evcc/util/request" ) -const CredentialsUri = "https://app.zendure.tech/eu/developer/api/apply" +const ( + EUCredentialsUri = "https://app.zendure.tech/eu/developer/api/apply" + GlobalCredentialsUri = "https://app.zendure.tech/v2/developer/api/apply" +) -func MqttCredentials(account, serial string) (CredentialsResponse, error) { +func MqttCredentials(account, serial string, global bool) (CredentialsResponse, error) { client := request.NewHelper(util.NewLogger("zendure")) data := CredentialsRequest{ @@ -18,7 +21,12 @@ func MqttCredentials(account, serial string) (CredentialsResponse, error) { Account: account, } - req, _ := request.New(http.MethodPost, CredentialsUri, request.MarshalJSON(data), request.JSONEncoding) + uri := EUCredentialsUri + if global { + uri = GlobalCredentialsUri + } + + req, _ := request.New(http.MethodPost, uri, request.MarshalJSON(data), request.JSONEncoding) var res CredentialsResponse err := client.DoJSON(req, &res) diff --git a/templates/definition/meter/zendure.yaml b/templates/definition/meter/zendure.yaml index f57b901722..ee930115fb 100644 --- a/templates/definition/meter/zendure.yaml +++ b/templates/definition/meter/zendure.yaml @@ -2,7 +2,7 @@ template: zendure products: - brand: Zendure description: - generic: Hyper V + generic: Hyper 2000 requirements: evcc: ["skiptest"] params: @@ -10,6 +10,10 @@ params: choice: ["pv", "battery"] - name: account - name: serial + - name: region + type: choice + default: EU + validvalues: ["EU", "Global"] - name: capacity default: 2 advanced: true