Support Audi and Tesla vehicle APIs (#20)

This commit is contained in:
andig 2020-03-29 21:15:44 +02:00 • committed by GitHub
parent 0a63ceb90a
commit ef6140cce5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 432 additions and 137 deletions

View file

@ -40,12 +40,10 @@ func (lp *LoadPoint) Configuration() Configuration {
ChargeMeter: lp.hasChargeMeter(),
}
if lp.SoC != nil {
if lp.Vehicle != nil {
c.SoC = true
if soc, ok := lp.SoC.(*SoC); ok {
c.SoCCapacity = soc.Capacity
c.SoCTitle = soc.Title
}
c.SoCCapacity = lp.Vehicle.Capacity()
c.SoCTitle = lp.Vehicle.Title()
}
return c
@ -58,11 +56,11 @@ func (lp *LoadPoint) hasChargeMeter() bool {
// Dump loadpoint configuration
func (lp *LoadPoint) Dump() {
soc := lp.SoC != nil
vehicle := lp.Vehicle != nil
grid := lp.GridMeter != nil
pv := lp.PVMeter != nil
log.INFO.Printf("%s config: soc %s grid %s pv %s charge %s", lp.Name,
presence[soc],
log.INFO.Printf("%s config: vehicle %s grid %s pv %s charge %s", lp.Name,
presence[vehicle],
presence[grid],
presence[pv],
presence[lp.hasChargeMeter()],
@ -121,11 +119,9 @@ func (lp *LoadPoint) remainingChargeDuration(chargePercent float64) time.Duratio
return -1
}
if lp.chargePower > 0 {
if soc, ok := lp.SoC.(*SoC); ok {
whRemaining := (1 - chargePercent/100.0) * 1e3 * float64(soc.Capacity)
return time.Duration(float64(time.Hour) * whRemaining / lp.chargePower)
}
if lp.chargePower > 0 && lp.Vehicle != nil {
whRemaining := (1 - chargePercent/100.0) * 1e3 * float64(lp.Vehicle.Capacity())
return time.Duration(float64(time.Hour) * whRemaining / lp.chargePower)
}
return -1
@ -133,19 +129,19 @@ func (lp *LoadPoint) remainingChargeDuration(chargePercent float64) time.Duratio
// publish state of charge and remaining charge duration
func (lp *LoadPoint) publishSoC() {
if lp.SoC == nil {
if lp.Vehicle == nil {
return
}
if lp.connected() {
f, err := lp.SoC.ChargeState()
f, err := lp.Vehicle.ChargeState()
if err == nil {
log.DEBUG.Printf("%s soc charge: %.1f%%", lp.Name, f)
log.DEBUG.Printf("%s vehicle charge: %.1f%%", lp.Name, f)
lp.publish("socCharge", f)
lp.publish("chargeEstimate", lp.remainingChargeDuration(f))
return
}
log.ERROR.Printf("%s soc error: %v", lp.Name, err)
log.ERROR.Printf("%s vehicle error: %v", lp.Name, err)
}
lp.publish("socCharge", "—")

View file

@ -46,14 +46,14 @@ type LoadPoint struct {
ChargeRater api.ChargeRater
// meters
GridMeter api.Meter // Grid usage meter
PVMeter api.Meter // PV generation meter
ChargeMeter api.Meter // Charger usage meter
SoC api.SoC // SoC
GridMeter api.Meter // Grid usage meter
PVMeter api.Meter // PV generation meter
ChargeMeter api.Meter // Charger usage meter
Vehicle api.Vehicle // Vehicle
// options
Steepness int64 // Step size of current change
Phases int64 // SOC phases. Required for converting power and current.
Phases int64 // Phases- required for converting power and current.
MinCurrent int64 // PV mode: start current Min+PV mode: min current
MaxCurrent int64 // Max allowed current. Physically ensured by the charge controller
Voltage float64 // Operating voltage. 230V for Germany.

View file

@ -1,27 +0,0 @@
package core
import (
"github.com/andig/evcc/api"
"github.com/andig/evcc/provider"
)
// SoC is an api.SoC implementation with configurable getters and setters.
type SoC struct {
Capacity int64
Title string
chargeG provider.FloatGetter
}
// NewSoC creates a new SoC
func NewSoC(capacity int64, title string, chargeG provider.FloatGetter) api.SoC {
return &SoC{
Capacity: capacity,
Title: title,
chargeG: chargeG,
}
}
// ChargeState implements the SoC.ChargeState interface
func (m *SoC) ChargeState() (float64, error) {
return m.chargeG()
}