From 41b7e0184cfe49b12386bea9a92ac8c29c4d5b8a Mon Sep 17 00:00:00 2001 From: Alex Savin Date: Tue, 3 Jun 2025 19:40:07 -0400 Subject: [PATCH] More changes --- vehicle.go | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/vehicle.go b/vehicle.go index 464c38d..2011fbd 100644 --- a/vehicle.go +++ b/vehicle.go @@ -685,7 +685,7 @@ func (v *Vehicle) GetVehicleCondition() { v.parseDoor("Door", "Position", typeOfS.Field(i).Name, val.Field(i).Interface()) } if strings.HasPrefix(typeOfS.Field(i).Name, "Door") && strings.HasSuffix(typeOfS.Field(i).Name, "LockStatus") { - v.parseDoor("Door", "LockStatus", typeOfS.Field(i).Name, val.Field(i).Interface()) + v.parseLock("Door", "LockStatus", typeOfS.Field(i).Name, val.Field(i).Interface()) } if strings.HasPrefix(typeOfS.Field(i).Name, "Window") && strings.HasSuffix(typeOfS.Field(i).Name, "Status") { v.parseWindow("Window", "Status", typeOfS.Field(i).Name, val.Field(i).Interface()) @@ -794,7 +794,7 @@ func (v *Vehicle) parseDoor(prefix, suffix, name string, value any) { pos := strings.TrimPrefix(name, prefix) pos = strings.TrimSuffix(pos, suffix) submatchall := re.FindAllString(pos, -1) - v.client.logger.Debug("VEHICLE COND", "key", name, "value", value, "number", len(submatchall)) + // v.client.logger.Debug("VEHICLE COND", "key", name, "value", value, "number", len(submatchall)) if door, ok := v.Doors[pos]; ok { door.Status = value.(string) @@ -816,13 +816,40 @@ func (v *Vehicle) parseDoor(prefix, suffix, name string, value any) { } } +// parseLock . +func (v *Vehicle) parseLock(prefix, suffix, name string, value any) { + re := regexp.MustCompile(`[A-Z][^A-Z]*`) + pos := strings.TrimPrefix(name, prefix) + pos = strings.TrimSuffix(pos, suffix) + submatchall := re.FindAllString(pos, -1) + // v.client.logger.Debug("VEHICLE COND", "key", name, "value", value, "number", len(submatchall)) + + if door, ok := v.Doors[pos]; ok { + door.Lock = value.(string) + } else { + door.Lock = value.(string) + door.Updated = time.Now() + v.Doors[pos] = Door{ + Position: submatchall[0], + Lock: value.(string), + Updated: time.Now(), + } + if len(submatchall) >= 2 { + if d, ok := v.Doors[pos]; ok { + d.SubPosition = submatchall[1] + v.Doors[pos] = d + } + } + } +} + // parseWindow . func (v *Vehicle) parseWindow(prefix, suffix, name string, value any) { re := regexp.MustCompile(`[A-Z][^A-Z]*`) pos := strings.TrimPrefix(name, prefix) pos = strings.TrimSuffix(pos, suffix) submatchall := re.FindAllString(pos, -1) - v.client.logger.Debug("VEHICLE COND", "key", name, "data", value, "number", len(submatchall)) + // v.client.logger.Debug("VEHICLE COND", "key", name, "data", value, "number", len(submatchall)) if window, ok := v.Windows[pos]; ok { window.Status = value.(string) @@ -850,7 +877,7 @@ func (v *Vehicle) parseTire(prefix, suffix, name string, value any) { pos := strings.TrimPrefix(name, prefix) pos = strings.TrimSuffix(pos, suffix) submatchall := re.FindAllString(pos, -1) - v.client.logger.Debug("VEHICLE COND", "key", name, "data", value, "number", len(submatchall)) + // v.client.logger.Debug("VEHICLE COND", "key", name, "data", value, "number", len(submatchall)) if tire, ok := v.Tires[pos]; ok { tire.PressurePsi = value.(string)