Skip to content

Commit

Permalink
Go-E: wait for slow updates (evcc-io#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Aug 10, 2021
1 parent d2b376f commit 5ee4e16
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions charger/go-e.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ func (c *GoE) apiStatus() (status goeStatusResponse, err error) {
// goeStatusResponse is only valid for local api. Use Fwv if valid.
func (c *GoE) apiUpdate(payload string) (goeStatusResponse, error) {
if c.token == "" {
// let charger settle after update
defer time.Sleep(2 * time.Second)
return c.localResponse("mqtt", payload)
}

Expand All @@ -143,11 +145,6 @@ func (c *GoE) apiUpdate(payload string) (goeStatusResponse, error) {
return status, err
}

// isValid checks is status response is local
func isValid(status goeStatusResponse) bool {
return status.Fwv != ""
}

// Status implements the api.Charger interface
func (c *GoE) Status() (api.ChargeStatus, error) {
status, err := c.apiStatus()
Expand Down Expand Up @@ -192,8 +189,10 @@ func (c *GoE) Enable(enable bool) error {
}

status, err := c.apiUpdate(fmt.Sprintf("alw=%d", b))
if err == nil && isValid(status) && status.Alw != b {
return fmt.Errorf("alw update failed: %d", status.Alw)
if err == nil {
if status, err = c.apiStatus(); err == nil && status.Alw != b {
return fmt.Errorf("alw update failed: %d", status.Alw)
}
}

return err
Expand All @@ -202,8 +201,10 @@ func (c *GoE) Enable(enable bool) error {
// MaxCurrent implements the api.Charger interface
func (c *GoE) MaxCurrent(current int64) error {
status, err := c.apiUpdate(fmt.Sprintf("amx=%d", current))
if err == nil && isValid(status) && int64(status.Amp) != current {
return fmt.Errorf("amp update failed: %d", status.Amp)
if err == nil {
if status, err = c.apiStatus(); err == nil && int64(status.Amp) != current {
return fmt.Errorf("amp update failed: %d", status.Amp)
}
}

return err
Expand Down

0 comments on commit 5ee4e16

Please sign in to comment.