Easee: Fix status out of sync when enabling (#1823)

This commit is contained in:
Michael Geers 2021-11-02 23:17:03 +01:00 • committed by GitHub
parent 4c2bb39cfd
commit 5ac1175091
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,15 +39,16 @@ import (
// Easee charger implementation
type Easee struct {
*request.Helper
charger string
updated time.Time
chargeStatus api.ChargeStatus
cache time.Duration
log *util.Logger
mux sync.Mutex
current float64
chargerEnabled bool
enabledStatus bool
charger string
updated time.Time
chargeStatus api.ChargeStatus
cache time.Duration
log *util.Logger
mux sync.Mutex
dynamicChargerCurrent float64
current float64
chargerEnabled bool
enabledStatus bool
currentPower, sessionEnergy,
currentL1, currentL2, currentL3 float64
}
@ -209,6 +210,14 @@ func (c *Easee) observe(typ string, i json.RawMessage) {
c.currentL2 = value.(float64)
case easee.IN_CURRENT_T5:
c.currentL3 = value.(float64)
case easee.DYNAMIC_CHARGER_CURRENT:
c.dynamicChargerCurrent = value.(float64)
// ensure that charger current matches evcc's expectation
if c.dynamicChargerCurrent > 0 && c.dynamicChargerCurrent != c.current {
if err = c.MaxCurrentMillis(c.current); err != nil {
c.log.ERROR.Println(err)
}
}
case easee.CHARGER_OP_MODE:
switch value.(int) {
case easee.ModeDisconnected:
@ -223,7 +232,10 @@ func (c *Easee) observe(typ string, i json.RawMessage) {
c.chargeStatus = api.StatusNone
c.log.ERROR.Printf("unknown opmode: %d", value.(int))
}
c.enabledStatus = value.(int) == easee.ModeCharging || value.(int) == easee.ModeReadyToCharge
c.enabledStatus = value.(int) == easee.ModeCharging ||
value.(int) == easee.ModeAwaitingStart ||
value.(int) == easee.ModeCompleted ||
value.(int) == easee.ModeReadyToCharge
}
c.log.TRACE.Printf("%s %s: %s %.4v", typ, res.Mid, res.ID, value)
@ -269,7 +281,7 @@ func (c *Easee) Enabled() (bool, error) {
c.mux.Lock()
defer c.mux.Unlock()
return c.enabledStatus, nil
return c.enabledStatus && c.dynamicChargerCurrent > 0, nil
}
// Enable implements the api.Charger interface
@ -301,11 +313,6 @@ func (c *Easee) Enable(enable bool) error {
uri := fmt.Sprintf("%s/chargers/%s/commands/%s", easee.API, c.charger, action)
_, err := c.Post(uri, request.JSONContent, nil)
if err == nil && action == easee.ChargeResume {
// restore current after enabling https://github.com/evcc-io/evcc/pull/1786
err = c.MaxCurrentMillis(c.current)
}
return err
}