Easee: wait for essential state during boot (#20646)

This commit is contained in:
Michael Heß 2025-04-16 16:16:44 +02:00 • committed by GitHub
parent 63c1c91484
commit 8ac4b659d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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