diff --git a/charger/easee.go b/charger/easee.go index e79390e0f..dc884043b 100644 --- a/charger/easee.go +++ b/charger/easee.go @@ -55,6 +55,7 @@ type Easee struct { smartCharging bool authorize bool enabled bool + initialStatePresent bool opMode int pilotMode string reasonForNoCurrent int @@ -334,9 +335,6 @@ func (c *Easee) ProductUpdate(i json.RawMessage) { c.opMode = opMode - // startup completed - c.startDone() - case easee.REASON_FOR_NO_CURRENT: c.reasonForNoCurrent = value.(int) case easee.PILOT_MODE: @@ -347,6 +345,22 @@ func (c *Easee) ProductUpdate(i json.RawMessage) { case c.obsC <- res: default: } + + if !c.initialStatePresent && c.checkInitialStatePresent() { + // startup completed + c.initialStatePresent = true + c.startDone() + } +} + +// check c.obsTime for presence of ALL of the following keys: easee.SESSION_ENERGY, easee.LIFETIME_ENERGY, easee.CHARGER_OP_MODE +func (c *Easee) checkInitialStatePresent() bool { + for _, key := range []easee.ObservationID{easee.SESSION_ENERGY, easee.LIFETIME_ENERGY, easee.CHARGER_OP_MODE, easee.TOTAL_POWER} { + if _, exists := c.obsTime[key]; !exists { + return false + } + } + return true } // ChargerUpdate implements the signalr receiver