Skip to content

Commit

Permalink
Custom vehicle: lower case parameters identical to plugin name (evcc-…
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored May 8, 2024
1 parent 52ca35f commit b9738ab
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion templates/definition/vehicle/teslalogger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ render: |
uri: {{ .url }}:{{ .port }}/command/{{ .id }}/wake_up
chargeEnable:
source: http
uri: {{ .url }}:{{ .port }}/command/{{ .id }}/charge_start_stop?${enable}
uri: {{ .url }}:{{ .port }}/command/{{ .id }}/charge_start_stop?${chargeenable}
maxcurrent:
source: http
uri: {{ .url }}:{{ .port }}/command/{{ .id }}/set_charging_amps?${maxcurrent}
4 changes: 2 additions & 2 deletions util/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/42atomys/sprout"
)

var re = regexp.MustCompile(`\${(\w+)(:([a-zA-Z0-9%.]+))?}`)
var re = regexp.MustCompile(`(?i)\${(\w+)(:([a-zA-Z0-9%.]+))?}`)

// Truish returns true if value is truish (true/1/on)
func Truish(s string) bool {
Expand Down Expand Up @@ -73,7 +73,7 @@ func ReplaceFormatted(s string, kv map[string]interface{}) (string, error) {
match, key, format := m[0], m[1], m[3]

// find key and replacement value
val, ok := kv[key]
val, ok := kv[strings.ToLower(key)]
if !ok {
wanted = append(wanted, key)
format = "%s"
Expand Down
14 changes: 7 additions & 7 deletions util/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"math"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestTruish(t *testing.T) {
Expand All @@ -21,10 +24,7 @@ func TestTruish(t *testing.T) {
}

for _, c := range cases {
b := Truish(c.k)
if b != c.v {
t.Errorf("expected %v got %v", c.v, b)
}
assert.Equal(t, c.v, Truish(c.k))
}
}

Expand All @@ -36,6 +36,7 @@ func TestReplace(t *testing.T) {
}{
// regex tests
{"foo", true, "${foo}", "true"},
{"foo", true, "${Foo}", "true"},
{"foo", "1", "abc${foo}${foo}", "abc11"},
{"foo", math.Pi, "${foo:%.2f}", "3.14"},
{"foo", math.Pi, "${foo:%.0f}%", "3%"},
Expand All @@ -47,9 +48,8 @@ func TestReplace(t *testing.T) {
c.k: c.v,
})

if s != c.expected || err != nil {
t.Error(s, err)
}
require.NoError(t, err)
assert.Equal(t, c.expected, s)
}
}

Expand Down
4 changes: 2 additions & 2 deletions vehicle/vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func NewConfigurableFromConfig(other map[string]interface{}) (api.Vehicle, error
// decorate maxCurrent
var maxCurrent func(int64) error
if cc.MaxCurrent != nil {
maxCurrent, err = provider.NewIntSetterFromConfig("maxCurrent", *cc.MaxCurrent)
maxCurrent, err = provider.NewIntSetterFromConfig("maxcurrent", *cc.MaxCurrent)
if err != nil {
return nil, fmt.Errorf("maxCurrent: %w", err)
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func NewConfigurableFromConfig(other map[string]interface{}) (api.Vehicle, error
// decorate chargeEnable
var chargeEnable func(bool) error
if cc.ChargeEnable != nil {
chargeEnable, err = provider.NewBoolSetterFromConfig("chargeEnable", *cc.ChargeEnable)
chargeEnable, err = provider.NewBoolSetterFromConfig("chargeenable", *cc.ChargeEnable)
if err != nil {
return nil, fmt.Errorf("chargeEnable: %w", err)
}
Expand Down

0 comments on commit b9738ab

Please sign in to comment.