Skip to content

Commit

Permalink
Zendure: add global region (#17224)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Nov 13, 2024
1 parent 00a3d40 commit 83d3b64
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
9 changes: 6 additions & 3 deletions meter/zendure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package meter

import (
"fmt"
"strings"
"time"

"github.com/evcc-io/evcc/api"
Expand All @@ -21,17 +22,19 @@ 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,
}

if err := util.DecodeOther(other, &cc); err != nil {
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
}
Expand Down
4 changes: 2 additions & 2 deletions meter/zendure/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
}
Expand Down
14 changes: 11 additions & 3 deletions meter/zendure/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ 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{
SnNumber: serial,
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)
Expand Down
6 changes: 5 additions & 1 deletion templates/definition/meter/zendure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ template: zendure
products:
- brand: Zendure
description:
generic: Hyper V
generic: Hyper 2000
requirements:
evcc: ["skiptest"]
params:
- name: usage
choice: ["pv", "battery"]
- name: account
- name: serial
- name: region
type: choice
default: EU
validvalues: ["EU", "Global"]
- name: capacity
default: 2
advanced: true
Expand Down

0 comments on commit 83d3b64

Please sign in to comment.