Skip to content

Commit

Permalink
Vehicles: make identifier matching case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Oct 18, 2022
1 parent e79505e commit c16f473
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/evcc-io/evcc/provider"
"github.com/evcc-io/evcc/push"
"github.com/evcc-io/evcc/util"
"golang.org/x/exp/slices"

evbus "github.com/asaskevich/EventBus"
"github.com/avast/retry-go/v3"
Expand Down Expand Up @@ -816,15 +815,18 @@ func (lp *LoadPoint) selectVehicleByID(id string) api.Vehicle {

// find exact match
for _, vehicle := range vehicles {
if slices.Contains(vehicle.Identifiers(), id) {
return vehicle
for _, vid := range vehicle.Identifiers() {
if strings.EqualFold(id, vid) {
return vehicle
}
}
}

// find placeholder match
for _, vehicle := range vehicles {
for _, vid := range vehicle.Identifiers() {
re, err := regexp.Compile(strings.ReplaceAll(vid, "*", ".*?"))
// case insensitive match
re, err := regexp.Compile("(?i)" + strings.ReplaceAll(vid, "*", ".*?"))
if err != nil {
lp.log.ERROR.Printf("vehicle id: %v", err)
continue
Expand Down

0 comments on commit c16f473

Please sign in to comment.