Vehicles: make identifier matching case insensitive

This commit is contained in:
andig 2022-10-18 12:52:12 +02:00
parent e79505e602
commit c16f473029

View file

@ -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"
@ -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