Skip to content

Commit

Permalink
Easee: wait for opmode to initialise (#11342)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Dec 30, 2023
1 parent 20fb3ed commit b887131
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions charger/easee.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ type Easee struct {
*request.Helper
charger string
site, circuit int
updated time.Time
lastEnergyPollTriggered time.Time
log *util.Logger
mux sync.Mutex
Expand Down Expand Up @@ -278,13 +277,6 @@ func (c *Easee) ProductUpdate(i json.RawMessage) {
c.mux.Lock()
defer c.mux.Unlock()

if c.updated.IsZero() {
defer once.Do(func() {
close(c.done)
})
}
c.updated = time.Now()

if prevTime, ok := c.obsTime[res.ID]; ok && prevTime.After(res.Timestamp) {
// received observation is outdated, ignoring
return
Expand Down Expand Up @@ -336,7 +328,7 @@ func (c *Easee) ProductUpdate(i json.RawMessage) {
c.sessionStartEnergy = nil
}

// OpMode changed TO charging. Start ticker for periodic requests to update LIFETIME_ENERGY
// OpMode changed to 3/charging. Start ticker for periodic requests to update LIFETIME_ENERGY
if c.opMode != easee.ModeCharging && opMode == easee.ModeCharging {
if c.stopTicker == nil {
c.stopTicker = make(chan struct{})
Expand All @@ -355,7 +347,7 @@ func (c *Easee) ProductUpdate(i json.RawMessage) {
}
}

// OpMode changed FROM >1 ("car connected") TO 1/disconnected - stop ticker if channel exists
// OpMode changed from >1 ("car connected") to 1/disconnected - stop ticker if channel exists
// channel may not exist regularly if the car was connected but charging never started
if c.opMode != easee.ModeDisconnected && opMode == easee.ModeDisconnected && c.stopTicker != nil {
close(c.stopTicker)
Expand All @@ -371,6 +363,11 @@ func (c *Easee) ProductUpdate(i json.RawMessage) {
c.requestLifetimeEnergyUpdate()
}

// startup completed
if c.opMode != 0 {
once.Do(func() { close(c.done) })
}

c.opMode = opMode

case easee.REASON_FOR_NO_CURRENT:
Expand Down

0 comments on commit b887131

Please sign in to comment.