EEBus: improve configure and charger handling (#5670)

This commit is contained in:
Andreas Linde 2023-01-06 16:37:46 +01:00 • committed by GitHub
parent 813b9f78af
commit 2e909588bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 5 deletions

View file

@ -3,6 +3,8 @@ package charger
import (
"errors"
"fmt"
"os"
"sync"
"time"
"github.com/enbility/cemd/emobility"
@ -10,6 +12,7 @@ import (
"github.com/evcc-io/evcc/core/loadpoint"
"github.com/evcc-io/evcc/server"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
)
const (
@ -35,6 +38,8 @@ type EEBus struct {
lastIsChargingResult bool
evConnectedTime time.Time
mux sync.Mutex
}
func init() {
@ -84,7 +89,29 @@ func NewEEBus(ski, ip string, hasMeter, hasChargedEnergy bool) (api.Charger, err
return decorateEEBus(c, c.currentPower, c.currents, nil), nil
}
return c, nil
// wait for first update
err := c.waitForInitialUpdate()
return c, err
}
// returns an error on failure
func (c *EEBus) waitForInitialUpdate() error {
// wait for a connection
timeout := time.After(request.Timeout)
tick := time.Tick(1 * time.Second)
// keep trying until we're timed out or got a positive result
for {
select {
case <-timeout:
return os.ErrDeadlineExceeded
case <-tick:
if c.isConnected() {
return nil
}
}
}
}
func (c *EEBus) onConnect(ski string) {
@ -110,12 +137,22 @@ func (c *EEBus) setDefaultValues() {
}
func (c *EEBus) setConnected(connected bool) {
c.mux.Lock()
defer c.mux.Unlock()
if connected && !c.connected {
c.evConnectedTime = time.Now()
}
c.connected = connected
}
func (c *EEBus) isConnected() bool {
c.mux.Lock()
defer c.mux.Unlock()
return c.connected
}
func (c *EEBus) setLoadpointMinMaxLimits() {
if c.lp == nil {
return
@ -186,7 +223,7 @@ func (c *EEBus) updateState() (api.ChargeStatus, error) {
return api.StatusNone, err
}
if !c.connected {
if !c.isConnected() {
return api.StatusNone, fmt.Errorf("%s charger reported as disconnected", c.ski)
}
@ -410,7 +447,7 @@ var _ api.Identifier = (*EEBus)(nil)
// Identify implements the api.Identifier interface
func (c *EEBus) Identify() (string, error) {
if !c.connected {
if !c.isConnected() {
return "", nil
}

View file

@ -86,6 +86,7 @@ func (d *DeviceTest) testCharger(v interface{}) (DeviceTestResult, error) {
if !ok {
return DeviceTestResultInvalid, errors.New("selected device is not a wallbox")
}
if _, err := c.Status(); err != nil {
return DeviceTestResultInvalid, err
}

View file

@ -63,7 +63,7 @@ Requirements_Sponsorship_Feature_Title = "Dies Verwendung dieser Funktionalität
Requirements_Sponsorship_Token = "Bist du ein Sponsor?"
Requirements_Sponsorship_Token_Input = "Bitte gib das Sponsortoken ein"
Requirements_EEBUS_Cert_Error = "Fehler: Das EEBUS Zertifikat konnte nicht erstellt werden"
Requirements_EEBUS_Pairing = "Du hast eine Wallbox ausgewählt, welche über das EEBUS Protokoll angesprochen wird.\nDazu muss die Wallbox nun mit evcc verbunden werden. Dies geschieht üblicherweise auf der Webseite der Wallbox.\nDrücke die Enter-Taste, wenn dies abgeschlossen ist."
Requirements_EEBUS_Pairing = "Du hast eine Wallbox ausgewählt, welche über das EEBUS Protokoll angesprochen wird.\nDazu muss die Wallbox nun mit evcc verbunden werden. Dies geschieht üblicherweise auf der Webseite der Wallbox.\nDrücke die Enter-Taste, wenn der Prozess gestartet ist."
Config_Title = "Führe folgende Einstellungen durch:"
Config_ModbusInterface = "Wähle die ModBus Schnittstelle aus"
Config_AddAnotherValue = "Möchtest du einen weiteren Wert hinzufügen?"

View file

@ -63,7 +63,7 @@ Requirements_Sponsorship_Feature_Title = "To use this feature a evcc sponsorship
Requirements_Sponsorship_Token = "Are you already a sponsor?"
Requirements_Sponsorship_Token_Input = "Please enter the sponsortoken"
Requirements_EEBUS_Cert_Error = "Error: The EEBUS certificate couldn't be created"
Requirements_EEBUS_Pairing = "You selected a wallbox, which will be accessed via the EEBUS protocol.\nFor that the wallbox needs to be connected to evcc. This can usually be done in the web interface of the wallbox.\nPlease press the enter key once this is done."
Requirements_EEBUS_Pairing = "You selected a wallbox, which will be accessed via the EEBUS protocol.\nFor that the wallbox needs to be connected to evcc. This can usually be done in the web interface of the wallbox.\nPlease press the enter key once you started the process."
Config_Title = "Please provide the following settings:"
Config_ModbusInterface = "Choose the ModBus interface"
Config_AddAnotherValue = "Do you want to add another value?"