Easee: update Smart Charging LED (#4031)

This commit is contained in:
Michael Geers 2022-08-05 19:48:59 +02:00 • committed by GitHub
parent 98406ef646
commit eb0d9ee73e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,7 @@ import (
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/easee"
"github.com/evcc-io/evcc/core/loadpoint"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/sponsor"
@ -50,11 +51,13 @@ type Easee struct {
dynamicChargerCurrent float64
current float64
chargerEnabled bool
smartCharging bool
enabledStatus bool
phaseMode int
currentPower, sessionEnergy,
currentL1, currentL2, currentL3 float64
rfid string
lp loadpoint.API
}
func init() {
@ -269,6 +272,8 @@ func (c *Easee) observe(typ string, i json.RawMessage) {
c.rfid = res.Value
case easee.IS_ENABLED:
c.chargerEnabled = value.(bool)
case easee.SMART_CHARGING:
c.smartCharging = value.(bool)
case easee.TOTAL_POWER:
c.currentPower = 1e3 * value.(float64)
case easee.SESSION_ENERGY:
@ -336,6 +341,8 @@ func (c *Easee) chargers() ([]easee.Charger, error) {
// Status implements the api.Charger interface
func (c *Easee) Status() (api.ChargeStatus, error) {
c.updateSmartCharging()
c.mux.L.Lock()
defer c.mux.L.Unlock()
@ -500,3 +507,40 @@ func (c *Easee) Identify() (string, error) {
return c.rfid, nil
}
// Set smart charging status to update the chargers led (smart=blue, fast=white)
func (c *Easee) updateSmartCharging() {
if c.lp == nil {
return
}
mode := c.lp.GetMode()
isSmartCharging := mode == api.ModePV || mode == api.ModeMinPV
c.mux.L.Lock()
updateNeeded := isSmartCharging != c.smartCharging
c.mux.L.Unlock()
if updateNeeded {
data := easee.ChargerSettings{
SmartCharging: &isSmartCharging,
}
uri := fmt.Sprintf("%s/chargers/%s/settings", easee.API, c.charger)
resp, err := c.Post(uri, request.JSONContent, request.MarshalJSON(data))
if err != nil {
c.log.WARN.Println("smart charging update failed:", err)
} else if resp.StatusCode != http.StatusAccepted {
resp.Body.Close()
c.log.WARN.Println("smart charging update failed:", resp.StatusCode, resp.Status)
}
c.mux.L.Lock()
c.smartCharging = isSmartCharging
c.mux.L.Unlock()
}
}
// LoadpointControl implements loadpoint.Controller
func (c *Easee) LoadpointControl(lp loadpoint.API) {
c.lp = lp
}