Warn if EVSE is always active (#153)
This commit is contained in:
parent
9bf987ff24
commit
4a1c029abd
2 changed files with 50 additions and 22 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/andig/evcc/api"
|
||||
"github.com/andig/evcc/util"
|
||||
|
|
@ -14,7 +15,7 @@ const (
|
|||
evseSetStatus apiFunction = "setStatus"
|
||||
evseSetCurrent apiFunction = "setCurrent"
|
||||
|
||||
evseSuccess = "S0_EVSE"
|
||||
evseSuccess = "S0_"
|
||||
)
|
||||
|
||||
// EVSEParameterResponse is the getParameters response
|
||||
|
|
@ -60,11 +61,9 @@ func NewEVSEWifiFromConfig(log *util.Logger, other map[string]interface{}) api.C
|
|||
func NewEVSEWifi(uri string) api.Charger {
|
||||
evse := &EVSEWifi{
|
||||
HTTPHelper: util.NewHTTPHelper(util.NewLogger("wifi")),
|
||||
uri: strings.TrimRight(uri, "/") + "/",
|
||||
uri: strings.TrimRight(uri, "/"),
|
||||
}
|
||||
|
||||
evse.HTTPHelper.Log.WARN.Println("-- experimental --")
|
||||
|
||||
return evse
|
||||
}
|
||||
|
||||
|
|
@ -72,20 +71,35 @@ func (evse *EVSEWifi) apiURL(service apiFunction) string {
|
|||
return fmt.Sprintf("%s/%s", evse.uri, service)
|
||||
}
|
||||
|
||||
// Status implements the Charger.Status interface
|
||||
func (evse *EVSEWifi) Status() (api.ChargeStatus, error) {
|
||||
// query evse parameters
|
||||
func (evse *EVSEWifi) getParameters() (EVSEListEntry, error) {
|
||||
var pr EVSEParameterResponse
|
||||
url := evse.apiURL(evseGetParameters)
|
||||
body, err := evse.GetJSON(url, &pr)
|
||||
if err != nil {
|
||||
return api.StatusNone, err
|
||||
return EVSEListEntry{}, err
|
||||
}
|
||||
|
||||
if len(pr.List) != 1 {
|
||||
return api.StatusNone, fmt.Errorf("unexpected response: %s", string(body))
|
||||
return EVSEListEntry{}, fmt.Errorf("unexpected response: %s", string(body))
|
||||
}
|
||||
|
||||
switch pr.List[0].VehicleState {
|
||||
params := pr.List[0]
|
||||
if params.AlwaysActive {
|
||||
evse.HTTPHelper.Log.WARN.Println("cannot control evse- alwaysactive is on")
|
||||
}
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// Status implements the Charger.Status interface
|
||||
func (evse *EVSEWifi) Status() (api.ChargeStatus, error) {
|
||||
params, err := evse.getParameters()
|
||||
if err != nil {
|
||||
return api.StatusNone, err
|
||||
}
|
||||
|
||||
switch params.VehicleState {
|
||||
case 1: // ready
|
||||
return api.StatusA, nil
|
||||
case 2: // EV is present
|
||||
|
|
@ -103,18 +117,8 @@ func (evse *EVSEWifi) Status() (api.ChargeStatus, error) {
|
|||
|
||||
// Enabled implements the Charger.Enabled interface
|
||||
func (evse *EVSEWifi) Enabled() (bool, error) {
|
||||
var pr EVSEParameterResponse
|
||||
url := evse.apiURL(evseGetParameters)
|
||||
body, err := evse.GetJSON(url, &pr)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if len(pr.List) != 1 {
|
||||
return false, fmt.Errorf("unexpected response: %s", string(body))
|
||||
}
|
||||
|
||||
return pr.List[0].EvseState, nil
|
||||
params, err := evse.getParameters()
|
||||
return params.EvseState, err
|
||||
}
|
||||
|
||||
// checkError checks for EVSE error response with HTTP 200 status
|
||||
|
|
@ -136,3 +140,27 @@ func (evse *EVSEWifi) MaxCurrent(current int64) error {
|
|||
url := fmt.Sprintf("%s?current=%d", evse.apiURL(evseSetCurrent), current)
|
||||
return evse.checkError(evse.Get(url))
|
||||
}
|
||||
|
||||
// ChargingTime yields current charge run duration
|
||||
func (evse *EVSEWifi) ChargingTime() (time.Duration, error) {
|
||||
params, err := evse.getParameters()
|
||||
return time.Duration(params.Duration) * time.Millisecond, err
|
||||
}
|
||||
|
||||
// // TotalEnergy implements the MeterEnergy interface
|
||||
// func (evse *EVSEWifi) TotalEnergy() (float64, error) {
|
||||
// params, err := evse.getParameters()
|
||||
// return params.MeterReading, err
|
||||
// }
|
||||
|
||||
// // ChargedEnergy implements the ChargeRater interface
|
||||
// func (evse *EVSEWifi) ChargedEnergy() (float64, error) {
|
||||
// params, err := evse.getParameters()
|
||||
// return params.Energy, err
|
||||
// }
|
||||
|
||||
// // Currents implements the MeterCurrents interface
|
||||
// func (evse *EVSEWifi) Currents() (float64, float64, float64, error) {
|
||||
// params, err := evse.getParameters()
|
||||
// return float64(params.CurrentP1), float64(params.CurrentP2), float64(params.CurrentP3), err
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -505,7 +505,7 @@ func (lp *LoadPoint) update() {
|
|||
|
||||
// read and publish status
|
||||
if err := retry.Do(lp.updateChargeStatus, retry.Attempts(3)); err != nil {
|
||||
log.ERROR.Printf("%s charger error: %v", lp.Name, err)
|
||||
log.ERROR.Printf("%s charge controller error: %v", lp.Name, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue