Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zendure: add global region #17224

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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