Skip to content

Commit

Permalink
Easee: fix completion of initial update sometimes not detected (#2210)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jan 6, 2022
1 parent 5fa0a3a commit 91b696f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions charger/easee.go
Expand Up @@ -165,14 +165,12 @@ func NewEasee(user, password, charger string, cache time.Duration) (*Easee, erro
}

// wait for first update
timer := time.NewTimer(request.Timeout)
done := make(chan struct{})

go c.waitForInitialUpdate(done)

select {
case <-done:
case <-timer.C:
case <-time.After(request.Timeout):
err = api.ErrTimeout
}

Expand Down Expand Up @@ -265,6 +263,13 @@ func (c *Easee) observe(typ string, i json.RawMessage) {

c.mux.L.Lock()
defer c.mux.L.Unlock()

if c.updated.IsZero() {
go func() {
<-time.After(3 * time.Second)
c.mux.Broadcast()
}()
}
c.updated = time.Now()

switch res.ID {
Expand Down Expand Up @@ -308,9 +313,6 @@ func (c *Easee) observe(typ string, i json.RawMessage) {
value.(int) == easee.ModeAwaitingStart ||
value.(int) == easee.ModeCompleted ||
value.(int) == easee.ModeReadyToCharge
case 219:
// HACK observation 219 is the last value received- broadcast to signal ready condition
c.mux.Broadcast()
}

c.log.TRACE.Printf("%s %s: %s %.4v", typ, res.Mid, res.ID, value)
Expand Down

0 comments on commit 91b696f

Please sign in to comment.