From 4369a36595eb5914a7edd072a7285c94f2245062 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 20 Mar 2022 17:24:40 +0100 Subject: [PATCH] Revert "EEBus: restore necessary variable expectedEnableState, fixed evConnectedTime handling (#2942)" This reverts commit 4425dd025e0cfee10f6f4fa177139080dd7a439a. --- charger/eebus.go | 56 +++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/charger/eebus.go b/charger/eebus.go index f654b6a9e..adbf55501 100644 --- a/charger/eebus.go +++ b/charger/eebus.go @@ -31,7 +31,6 @@ type EEBus struct { maxCurrent float64 connected bool - expectedEnableState bool evConnectedTime time.Time } @@ -74,14 +73,14 @@ func NewEEBus(ski string, forcePVLimits bool) (*EEBus, error) { } func (c *EEBus) onConnect(ski string, conn ship.Conn) error { - c.log.TRACE.Println("!! onConnect invoked on ski ", ski) + c.log.TRACE.Println("!! onCconnect invoked on ski ", ski) eebusDevice := app.HEMS(server.EEBusInstance.DeviceInfo()) c.cc = communication.NewConnectionController(c.log.TRACE, conn, eebusDevice) c.cc.SetDataUpdateHandler(c.dataUpdateHandler) + c.connected = true c.setDefaultValues() - c.setConnected(true) err := c.cc.Boot() @@ -91,24 +90,16 @@ func (c *EEBus) onConnect(ski string, conn ship.Conn) error { func (c *EEBus) onDisconnect(ski string) { c.log.TRACE.Println("!! onDisconnect invoked on ski ", ski) - c.setConnected(false) + c.connected = false c.setDefaultValues() } func (c *EEBus) setDefaultValues() { - c.expectedEnableState = false c.communicationStandard = communication.EVCommunicationStandardEnumTypeUnknown c.socSupportAvailable = false c.selfConsumptionSupportAvailable = false } -func (c *EEBus) setConnected(connected bool) { - if connected && !c.connected { - c.evConnectedTime = time.Now() - } - c.connected = connected -} - func (c *EEBus) setLoadpointMinMaxLimits(data *communication.EVSEClientDataType) { if c.lp == nil { return @@ -161,7 +152,7 @@ func (c *EEBus) showCurrentChargingSetup() { func (c *EEBus) dataUpdateHandler(dataType communication.EVDataElementUpdateType, data *communication.EVSEClientDataType) { // we receive data, so it is connected - c.setConnected(true) + c.connected = true c.showCurrentChargingSetup() @@ -174,9 +165,6 @@ func (c *EEBus) dataUpdateHandler(dataType communication.EVDataElementUpdateType } // case communication.EVDataElementUpdateUseCaseSoC: case communication.EVDataElementUpdateEVConnectionState: - if data.EVData.ChargeState == communication.EVChargeStateEnumTypeUnplugged { - c.expectedEnableState = false - } c.setLoadpointMinMaxLimits(data) case communication.EVDataElementUpdateCommunicationStandard: c.communicationStandard = data.EVData.CommunicationStandard @@ -201,7 +189,8 @@ func isCharging(d communication.EVDataType) bool { d.Measurements.PowerL3 > d.LimitsL3.Min*idleFactor } -func updateState() (api.ChargeStatus, error) { +// Status implements the api.Charger interface +func (c *EEBus) Status() (api.ChargeStatus, error) { data, err := c.cc.GetData() if err != nil { c.log.TRACE.Printf("!! status: no eebus data available yet") @@ -217,14 +206,12 @@ func updateState() (api.ChargeStatus, error) { switch currentState { case communication.EVChargeStateEnumTypeUnknown, communication.EVChargeStateEnumTypeUnplugged: // Unplugged - c.expectedEnableState = false + c.evConnectedTime = time.Now() return api.StatusA, nil case communication.EVChargeStateEnumTypeFinished, communication.EVChargeStateEnumTypePaused: // Finished, Paused return api.StatusB, nil case communication.EVChargeStateEnumTypeActive: // Active if isCharging(data.EVData) { - // we might already be enabled and charging due to connection issues - c.expectedEnableState = true return api.StatusC, nil } return api.StatusB, nil @@ -235,16 +222,29 @@ func updateState() (api.ChargeStatus, error) { return api.StatusNone, fmt.Errorf("properties unknown result: %s", currentState) } -// Status implements the api.Charger interface -func (c *EEBus) Status() (api.ChargeStatus, error) { - return updateState -} - // Enabled implements the api.Charger interface // should return true if the charger allows the EV to draw power func (c *EEBus) Enabled() (bool, error) { - status, err := updateState - return c.expectedEnableState, err + var res bool + + // we might already be enabled and charging due to connection issues + data, err := c.cc.GetData() + if err == nil { + // handle ev being disconnected + if data.EVData.ChargeState != communication.EVChargeStateEnumTypeUnplugged && + data.EVData.ChargeState != communication.EVChargeStateEnumTypeUnknown { + + var status api.ChargeStatus + if status, err = c.Status(); err == nil { + if status == api.StatusB || status == api.StatusC { + res = isCharging(data.EVData) + } + } + } + } + + // return the save enable state as we assume enabling/disabling always works + return res, err } // Enable implements the api.Charger interface @@ -275,8 +275,6 @@ func (c *EEBus) Enable(enable bool) error { return api.ErrMustRetry } - c.expectedEnableState = enable - if !enable { // Important notes on enabling/disabling!! // ISO15118 mode: