Zendure: add global region (#17224)

This commit is contained in:
andig 2024-11-13 10:39:50 +01:00 • committed by GitHub
parent 00a3d40218
commit 83d3b64520
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 9 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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)

View file

@ -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