Easee: remove custom logic based on erratic lifetime_energy (#20668)

This commit is contained in:
Michael Heß 2025-04-18 10:45:43 +02:00 • committed by GitHub
parent bb22b0f5bc
commit e08016f6e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 58 deletions

View file

@ -60,7 +60,6 @@ type Easee struct {
pilotMode string
reasonForNoCurrent int
phaseMode int
sessionStartEnergy *float64
currentPower, sessionEnergy, totalEnergy,
currentL1, currentL2, currentL3 float64
rfid string
@ -294,11 +293,6 @@ func (c *Easee) ProductUpdate(i json.RawMessage) {
c.sessionEnergy = value.(float64)
case easee.LIFETIME_ENERGY:
c.totalEnergy = value.(float64)
// Remember value of LIFETIME_ENERGY as start value of the charging session
if c.sessionStartEnergy == nil {
f := c.totalEnergy
c.sessionStartEnergy = &f
}
case easee.IN_CURRENT_T3:
c.currentL1 = value.(float64)
case easee.IN_CURRENT_T4:
@ -317,17 +311,8 @@ func (c *Easee) ProductUpdate(i json.RawMessage) {
c.maxChargerCurrent = value.(float64)
case easee.DYNAMIC_CHARGER_CURRENT:
c.dynamicChargerCurrent = value.(float64)
case easee.CHARGER_OP_MODE:
opMode := value.(int)
// New charging session pending, reset sessionStartEnergy
if c.opMode <= easee.ModeDisconnected && opMode >= easee.ModeAwaitingStart {
c.sessionStartEnergy = nil
}
c.opMode = opMode
c.opMode = value.(int)
case easee.REASON_FOR_NO_CURRENT:
c.reasonForNoCurrent = value.(int)
case easee.PILOT_MODE:
@ -678,14 +663,6 @@ var _ api.ChargeRater = (*Easee)(nil)
func (c *Easee) ChargedEnergy() (float64, error) {
c.mux.RLock()
defer c.mux.RUnlock()
// return either the self calced session energy (current LIFETIME_ENERGY minus remembered start value),
// or the SESSION_ENERGY value by the API. Each value could be lower than the other, depending on
// order and receive timestamp of the product update. We want to return the higher (and newer) value.
if c.sessionStartEnergy != nil {
return max(c.sessionEnergy, c.totalEnergy-*c.sessionStartEnergy), nil
}
return c.sessionEnergy, nil
}
@ -704,6 +681,8 @@ var _ api.MeterEnergy = (*Easee)(nil)
func (c *Easee) TotalEnergy() (float64, error) {
c.mux.RLock()
defer c.mux.RUnlock()
// updates for this are only sent once an hour, so inaccurate by design
// see also https://github.com/evcc-io/evcc/issues/20594
return c.totalEnergy, nil
}

View file

@ -49,37 +49,3 @@ func TestProductUpdate_IgnoreOutdatedProductUpdate(t *testing.T) {
assert.Equal(t, now, e.obsTime[easee.CHARGER_OP_MODE])
assert.Equal(t, 2, e.opMode)
}
func TestProductUpdate_LifetimeEnergyAndSessionStartEnergy(t *testing.T) {
e := newEasee()
now := time.Now().UTC().Truncate(0)
e.ProductUpdate(createPayload(easee.LIFETIME_ENERGY, now, easee.Double, "20"))
assert.Equal(t, now, e.obsTime[easee.LIFETIME_ENERGY])
assert.Equal(t, float64(20), e.totalEnergy)
assert.Equal(t, float64(20), *e.sessionStartEnergy)
t2 := time.Now().UTC().Truncate(0)
e.ProductUpdate(createPayload(easee.LIFETIME_ENERGY, t2, easee.Double, "40"))
assert.Equal(t, t2, e.obsTime[easee.LIFETIME_ENERGY])
assert.Equal(t, float64(40), e.totalEnergy)
assert.Equal(t, float64(20), *e.sessionStartEnergy)
}
func TestProductUpdate_ChargeStartSessionEnergy(t *testing.T) {
e := newEasee()
t_minus_5 := time.Now().UTC().Truncate(0).Add(-5 * time.Second)
e.ProductUpdate(createPayload(easee.CHARGER_OP_MODE, t_minus_5, easee.Integer, "2"))
assert.Equal(t, t_minus_5, e.obsTime[easee.CHARGER_OP_MODE])
assert.Equal(t, 2, e.opMode)
assert.Nil(t, e.sessionStartEnergy)
assert.Equal(t, float64(0), e.sessionEnergy)
assert.NotEqual(t, t_minus_5, e.obsTime[easee.SESSION_ENERGY])
}