Skip to content

Commit

Permalink
Revert "Easee: wait for opmode to initialise (#11342)"
Browse files Browse the repository at this point in the history
This reverts commit b887131.
  • Loading branch information
andig committed Jan 2, 2024
1 parent 7320e73 commit 7819662
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions charger/easee.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ 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 @@ -277,6 +278,13 @@ 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 @@ -328,7 +336,7 @@ func (c *Easee) ProductUpdate(i json.RawMessage) {
c.sessionStartEnergy = nil
}

// OpMode changed to 3/charging. Start ticker for periodic requests to update LIFETIME_ENERGY
// OpMode changed TO 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 @@ -347,7 +355,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 @@ -363,11 +371,6 @@ 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 7819662

Please sign in to comment.