Zendure: add global region (#17224)
This commit is contained in:
parent
00a3d40218
commit
83d3b64520
4 changed files with 24 additions and 9 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue