Skip to content

Commit

Permalink
Merge branch 'master' into add-schedule-for-planner
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis authored Nov 19, 2024
2 parents 645c1f9 + 9083a84 commit 1c3eeca
Show file tree
Hide file tree
Showing 9 changed files with 369 additions and 341 deletions.
4 changes: 4 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ builds:
goarch: arm
- goos: windows
goarch: arm64
overrides:
- goos: darwin
ldflags:
- "-B gobuildid"

env:
- CGO_ENABLED=0
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ build::
CGO_ENABLED=0 go build -v $(BUILD_TAGS) $(BUILD_ARGS)

snapshot::
goreleaser --snapshot --skip-publish --clean
goreleaser --snapshot --skip publish --clean

release::
goreleaser --clean
Expand Down
27 changes: 23 additions & 4 deletions charger/easee.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Easee struct {
lastEnergyPollMux sync.Mutex
maxChargerCurrent float64
dynamicChargerCurrent float64
dynamicCircuitCurrent [3]float64
current float64
chargerEnabled bool
smartCharging bool
Expand All @@ -61,7 +62,6 @@ type Easee struct {
pilotMode string
reasonForNoCurrent int
phaseMode int
outputPhase int
sessionStartEnergy *float64
currentPower, sessionEnergy, totalEnergy,
currentL1, currentL2, currentL3 float64
Expand Down Expand Up @@ -313,8 +313,12 @@ func (c *Easee) ProductUpdate(i json.RawMessage) {
c.currentL3 = value.(float64)
case easee.PHASE_MODE:
c.phaseMode = value.(int)
case easee.OUTPUT_PHASE:
c.outputPhase = value.(int) / 10 // API gives 0,10,30 for 0,1,3p
case easee.DYNAMIC_CIRCUIT_CURRENT_P1:
c.dynamicCircuitCurrent[0] = value.(float64)
case easee.DYNAMIC_CIRCUIT_CURRENT_P2:
c.dynamicCircuitCurrent[1] = value.(float64)
case easee.DYNAMIC_CIRCUIT_CURRENT_P3:
c.dynamicCircuitCurrent[2] = value.(float64)
case easee.MAX_CHARGER_CURRENT:
c.maxChargerCurrent = value.(float64)
case easee.DYNAMIC_CHARGER_CURRENT:
Expand Down Expand Up @@ -814,7 +818,22 @@ var _ api.PhaseGetter = (*Easee)(nil)
func (c *Easee) GetPhases() (int, error) {
c.mux.RLock()
defer c.mux.RUnlock()
return c.outputPhase, nil
var phases int
if c.circuit != 0 {
// circuit level controlled charger
for _, dcc := range c.dynamicCircuitCurrent {
if dcc > 0 {
phases++
}
}
} else {
// charger level
phases = c.phaseMode
if phases == 2 { // map automatic to 3p
phases = 3
}
}
return phases, nil
}

var _ api.Identifier = (*Easee)(nil)
Expand Down
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
Loading

0 comments on commit 1c3eeca

Please sign in to comment.