Skip to content

Commit

Permalink
Improve vehicle declaration and add initial configuration test
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Apr 6, 2020
1 parent cf89044 commit 4addd95
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 12 deletions.
23 changes: 23 additions & 0 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"bytes"
"os"
"testing"

"github.com/spf13/viper"
Expand Down Expand Up @@ -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)
}
54 changes: 50 additions & 4 deletions evcc.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 17 additions & 7 deletions vehicle/tesla.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion vehicle/vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down

0 comments on commit 4addd95

Please sign in to comment.