Improve vehicle declaration and add initial configuration test
This commit is contained in:
parent
cf89044898
commit
4addd9516c
4 changed files with 92 additions and 12 deletions
|
|
@ -2,6 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
|
@ -48,3 +49,25 @@ chargers:
|
|||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDistConfig(t *testing.T) {
|
||||
file := "../evcc.dist.yaml"
|
||||
yaml, err := os.Open(file)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
viper.SetConfigType("yaml")
|
||||
if err := viper.ReadConfig(yaml); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// check config does not contain surplus keys
|
||||
var conf config
|
||||
if err := viper.UnmarshalExact(&conf); err != nil {
|
||||
log.FATAL.Fatalf("config: failed parsing config file %s: %v", cfgFile, err)
|
||||
}
|
||||
|
||||
// check config is valid
|
||||
loadConfig(conf, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,13 +64,59 @@ chargers:
|
|||
type: wallbe # Wallbe charger using Phoenix Contact controller
|
||||
uri: 192.168.0.8:502 # ModBus address
|
||||
|
||||
vehicles:
|
||||
- name: script
|
||||
type: script
|
||||
title: Script
|
||||
capacity: 50 # kWh
|
||||
charge:
|
||||
type: script # use script
|
||||
cmd: /bin/sh -c "echo 50" # actual command
|
||||
timeout: 3s # kill script after 3 seconds
|
||||
cache: 5m
|
||||
- name: audi
|
||||
type: audi
|
||||
title: Q55 TFSIe
|
||||
capacity: 10 # kWh
|
||||
user: # user
|
||||
password: # password
|
||||
vin: WAUZZZ...
|
||||
cache: 5m
|
||||
- name: bmw
|
||||
type: bmw
|
||||
title: i3
|
||||
capacity: 65 # kWh
|
||||
user: # user
|
||||
password: # password
|
||||
vin: WBMW...
|
||||
cache: 5m
|
||||
# - name: tesla
|
||||
# type: tesla
|
||||
# title: Model S
|
||||
# capacity: 90 # kWh
|
||||
# clientid: # client id
|
||||
# clientsecret: # client secret
|
||||
# email: # email
|
||||
# password: # password
|
||||
# vin: WTSLA...
|
||||
# cache: 5m
|
||||
# - name: nissan
|
||||
# type: nissan
|
||||
# title: Leaf
|
||||
# capacity: 60 # kWh
|
||||
# user: # user
|
||||
# password: # password
|
||||
# region: NE # carwings region, leave empty for Europe
|
||||
# cache: 5m
|
||||
|
||||
loadpoints:
|
||||
- name: lp1 # name for logging
|
||||
steepness: 1 # raise/lower charge current in 1A steps
|
||||
guardduration: 10m # switch charger contactor not more often than this (default 10m)
|
||||
maxcurrent: 16 # maximum charge current (default 16A)
|
||||
phases: 3 # ev phases (default 3)
|
||||
vehicle: audi
|
||||
charger: wallbe # charger
|
||||
gridmeter: grid # grid meter
|
||||
pvmeter: pv # pv meter
|
||||
chargemeter: charge # charge meter
|
||||
steepness: 1 # raise/lower charge current in 1A steps
|
||||
guardduration: 10m # switch charger contactor not more often than this (default 10m)
|
||||
maxcurrent: 16 # maximum charge current (default 16A)
|
||||
phases: 3 # ev phases (default 3)
|
||||
|
|
|
|||
|
|
@ -19,11 +19,12 @@ type Tesla struct {
|
|||
// NewTeslaFromConfig creates a new Tesla vehicle
|
||||
func NewTeslaFromConfig(log *api.Logger, other map[string]interface{}) api.Vehicle {
|
||||
cc := struct {
|
||||
Title string
|
||||
Capacity int64
|
||||
ClientID, ClientSecret, Email, Password string
|
||||
Vehicle int
|
||||
Cache time.Duration
|
||||
Title string
|
||||
Capacity int64
|
||||
ClientID, ClientSecret string
|
||||
Email, Password string
|
||||
VIN string
|
||||
Cache time.Duration
|
||||
}{}
|
||||
api.DecodeOther(log, other, &cc)
|
||||
|
||||
|
|
@ -43,8 +44,17 @@ func NewTeslaFromConfig(log *api.Logger, other map[string]interface{}) api.Vehic
|
|||
}
|
||||
|
||||
v := &Tesla{
|
||||
embed: &embed{cc.Title, cc.Capacity},
|
||||
vehicle: vehicles[0].Vehicle,
|
||||
embed: &embed{cc.Title, cc.Capacity},
|
||||
}
|
||||
|
||||
for _, vehicle := range vehicles {
|
||||
if vehicle.Vin == cc.VIN {
|
||||
v.vehicle = vehicle.Vehicle
|
||||
}
|
||||
}
|
||||
|
||||
if v.vehicle == nil {
|
||||
log.FATAL.Fatal("cannot create tesla: vin not found")
|
||||
}
|
||||
|
||||
v.chargeStateG = provider.NewCached(v.chargeState, cc.Cache).FloatGetter()
|
||||
|
|
|
|||
|
|
@ -38,12 +38,13 @@ func NewConfigurableFromConfig(log *api.Logger, other map[string]interface{}) ap
|
|||
Title string
|
||||
Capacity int64
|
||||
Charge *provider.Config
|
||||
Cache time.Duration
|
||||
}{}
|
||||
api.DecodeOther(log, other, &cc)
|
||||
|
||||
return &Vehicle{
|
||||
embed: &embed{cc.Title, cc.Capacity},
|
||||
chargeG: provider.NewFloatGetterFromConfig(cc.Charge),
|
||||
chargeG: provider.NewCached(provider.NewFloatGetterFromConfig(cc.Charge), cc.Cache).FloatGetter(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue