From 8ac4b659d4a94f609b01ef09be374b2c125e629c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20He=C3=9F?= Date: Wed, 16 Apr 2025 16:16:44 +0200 Subject: [PATCH] Easee: wait for essential state during boot (#20646) --- charger/easee.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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