Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Nov 18, 2024
2 parents aebc30f + 3148c4f commit 32296c2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions meter/zendure.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ func NewZendureFromConfig(other map[string]interface{}) (api.Meter, error) {
return nil, err
}

global := strings.ToUpper(cc.Region) != "EU"
conn, err := zendure.NewConnection(cc.Account, cc.Serial, global, cc.Timeout)
conn, err := zendure.NewConnection(strings.ToUpper(cc.Region), cc.Account, cc.Serial, cc.Timeout)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 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, global bool, timeout time.Duration) (*Connection, error) {
func NewConnection(region, account, serial string, timeout time.Duration) (*Connection, error) {
mu.Lock()
defer mu.Unlock()

Expand All @@ -31,12 +31,12 @@ func NewConnection(account, serial string, global bool, timeout time.Duration) (
return conn, nil
}

res, err := MqttCredentials(account, serial, global)
log := util.NewLogger("zendure")
res, err := MqttCredentials(log, region, account, serial)
if err != nil {
return nil, err
}

log := util.NewLogger("zendure")
client, err := mqtt.NewClient(
log,
net.JoinHostPort(res.Data.MqttUrl, strconv.Itoa(res.Data.Port)), res.Data.AppKey, res.Data.Secret,
Expand Down
10 changes: 5 additions & 5 deletions meter/zendure/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ const (
GlobalCredentialsUri = "https://app.zendure.tech/v2/developer/api/apply"
)

func MqttCredentials(account, serial string, global bool) (CredentialsResponse, error) {
client := request.NewHelper(util.NewLogger("zendure"))
func MqttCredentials(log *util.Logger, region, account, serial string) (CredentialsResponse, error) {
client := request.NewHelper(log)

data := CredentialsRequest{
SnNumber: serial,
Account: account,
}

uri := EUCredentialsUri
if global {
uri = GlobalCredentialsUri
uri := GlobalCredentialsUri
if region == "EU" {
uri = EUCredentialsUri
}

req, _ := request.New(http.MethodPost, uri, request.MarshalJSON(data), request.JSONEncoding)
Expand Down

0 comments on commit 32296c2

Please sign in to comment.