Changed the way of parsing parts
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 24s

This commit is contained in:
2025-06-05 14:11:08 -04:00
parent 15a792ac9b
commit 91c3c44b54

View File

@ -633,16 +633,16 @@ func (v *Vehicle) GetVehicleStatus() {
continue continue
} else { } else {
if strings.HasPrefix(typeOfS.Field(i).Name, "Door") && strings.HasSuffix(typeOfS.Field(i).Name, "Position") { if strings.HasPrefix(typeOfS.Field(i).Name, "Door") && strings.HasSuffix(typeOfS.Field(i).Name, "Position") {
v.parseDoor("Door", "Position", typeOfS.Field(i).Name, val.Field(i).Interface()) v.parseParts(typeOfS.Field(i).Name, val.Field(i).Interface())
}
if strings.HasPrefix(typeOfS.Field(i).Name, "Door") && strings.HasSuffix(typeOfS.Field(i).Name, "LockStatus") {
v.parseLock("Door", "LockStatus", typeOfS.Field(i).Name, val.Field(i).Interface())
} }
// if strings.HasPrefix(typeOfS.Field(i).Name, "Door") && strings.HasSuffix(typeOfS.Field(i).Name, "LockStatus") {
// 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") { 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()) v.parseParts(typeOfS.Field(i).Name, val.Field(i).Interface())
} }
if strings.HasPrefix(typeOfS.Field(i).Name, "TirePressure") && strings.HasSuffix(typeOfS.Field(i).Name, "Psi") { if strings.HasPrefix(typeOfS.Field(i).Name, "TirePressure") && strings.HasSuffix(typeOfS.Field(i).Name, "Psi") {
v.parseTirePsi("TirePressure", "Psi", typeOfS.Field(i).Name, val.Field(i).Interface()) v.parseParts(typeOfS.Field(i).Name, val.Field(i).Interface())
} }
} }
} }
@ -682,14 +682,14 @@ func (v *Vehicle) GetVehicleCondition() {
continue continue
} else { } else {
if strings.HasPrefix(typeOfS.Field(i).Name, "Door") && strings.HasSuffix(typeOfS.Field(i).Name, "Position") { if strings.HasPrefix(typeOfS.Field(i).Name, "Door") && strings.HasSuffix(typeOfS.Field(i).Name, "Position") {
v.parseDoor("Door", "Position", typeOfS.Field(i).Name, val.Field(i).Interface()) v.parseParts(typeOfS.Field(i).Name, val.Field(i).Interface())
} }
if strings.HasPrefix(typeOfS.Field(i).Name, "Window") && strings.HasSuffix(typeOfS.Field(i).Name, "Status") { 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()) v.parseParts(typeOfS.Field(i).Name, val.Field(i).Interface())
}
if strings.HasPrefix(typeOfS.Field(i).Name, "TirePressure") && !strings.HasSuffix(typeOfS.Field(i).Name, "Unit") {
v.parseTire("TirePressure", "", typeOfS.Field(i).Name, val.Field(i).Interface())
} }
// if strings.HasPrefix(typeOfS.Field(i).Name, "TirePressure") && !strings.HasSuffix(typeOfS.Field(i).Name, "Unit") {
// v.parseTire("TirePressure", "", typeOfS.Field(i).Name, val.Field(i).Interface())
// }
// if strings.HasPrefix(typeOfS.Field(i).Name, "Door") && strings.HasSuffix(typeOfS.Field(i).Name, "LockStatus") { // if strings.HasPrefix(typeOfS.Field(i).Name, "Door") && strings.HasSuffix(typeOfS.Field(i).Name, "LockStatus") {
// v.parseLock("Door", "LockStatus", typeOfS.Field(i).Name, val.Field(i).Interface()) // v.parseLock("Door", "LockStatus", typeOfS.Field(i).Name, val.Field(i).Interface())
// } // }
@ -790,139 +790,182 @@ func (v *Vehicle) getRemoteOptionsStatus() bool {
} }
// parseDoor . // parseDoor .
func (v *Vehicle) parseDoor(prefix, suffix, name string, value any) { func (v *Vehicle) parseParts(name string, value any) {
re := regexp.MustCompile(`[A-Z][^A-Z]*`) // re := regexp.MustCompile(`[A-Z][^A-Z]*`)
pos := strings.TrimPrefix(name, prefix) re := regexp.MustCompile(`([Dd]oor|[Ww]indow|[Tt]ire)(?:[Pp]ressure)?([Ff]ront|[Rr]ear|[Bb]oot|[Ee]ngine[Hh]ood|[Ss]unroof)([Ll]eft|[Rr]ight)?(?:[Pp]osition|[Ss]tatus|[Ll]ock[Ss]tatus|[Pp]si)?`)
pos = strings.TrimSuffix(pos, suffix) grps := re.FindStringSubmatch(name)
submatchall := re.FindAllString(pos, -1)
pn := strings.ToLower(grps[1] + "_" + grps[2])
if len(grps[2]) > 0 {
pn = pn + "_" + grps[3]
}
// 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 d, ok := v.Doors[pos]; ok { switch grps[1] {
d.Status = value.(string) case "Door", "door":
d.Updated = time.Now() if d, ok := v.Doors[pn]; ok {
v.Doors[pos] = d d.Status = value.(string)
} else { d.Updated = time.Now()
v.Doors[pos] = Door{ v.Doors[pn] = d
Position: submatchall[0], } else {
Status: value.(string), v.Doors[pn] = Door{
Updated: time.Now(), Position: grps[2],
Status: value.(string),
Updated: time.Now(),
}
if len(grps) >= 2 {
if d, ok := v.Doors[pn]; ok {
d.SubPosition = grps[3]
v.Doors[pn] = d
}
}
} }
if len(submatchall) >= 2 { case "Window", "window":
if d, ok := v.Doors[pos]; ok { if w, ok := v.Windows[pn]; ok {
d.SubPosition = submatchall[1] w.Status = value.(string)
v.Doors[pos] = d w.Updated = time.Now()
v.Windows[pn] = w
} else {
v.Windows[pn] = Window{
Position: grps[2],
Status: value.(string),
Updated: time.Now(),
}
if len(grps) >= 2 {
if w, ok := v.Windows[pn]; ok {
w.SubPosition = grps[3]
v.Windows[pn] = w
}
}
}
case "Tire", "tire":
if t, ok := v.Tires[pn]; ok {
t.PressurePsi = value.(int)
t.Updated = time.Now()
v.Tires[pn] = t
} else {
v.Tires[pn] = Tire{
Position: grps[2],
PressurePsi: value.(int),
Updated: time.Now(),
}
if len(grps) >= 2 {
if t, ok := v.Tires[pn]; ok {
t.SubPosition = grps[3]
v.Tires[pn] = t
}
} }
} }
} }
} }
// parseLock . // parseLock .
func (v *Vehicle) parseLock(prefix, suffix, name string, value any) { // func (v *Vehicle) parseLock(prefix, suffix, name string, value any) {
re := regexp.MustCompile(`[A-Z][^A-Z]*`) // re := regexp.MustCompile(`[A-Z][^A-Z]*`)
pos := strings.TrimPrefix(name, prefix) // pos := strings.TrimPrefix(name, prefix)
pos = strings.TrimSuffix(pos, suffix) // pos = strings.TrimSuffix(pos, suffix)
submatchall := re.FindAllString(pos, -1) // submatchall := re.FindAllString(pos, -1)
// v.client.logger.Debug("door lock status", "key", name, "value", value, "number", len(submatchall)) // // v.client.logger.Debug("door lock status", "key", name, "value", value, "number", len(submatchall))
if d, ok := v.Doors[pos]; ok { // if d, ok := v.Doors[pos]; ok {
d.Lock = value.(string) // d.Lock = value.(string)
d.Updated = time.Now() // d.Updated = time.Now()
v.Doors[pos] = d // v.Doors[pos] = d
} else { // } else {
v.Doors[pos] = Door{ // v.Doors[pos] = Door{
Position: submatchall[0], // Position: submatchall[0],
Lock: value.(string), // Lock: value.(string),
Updated: time.Now(), // Updated: time.Now(),
} // }
if len(submatchall) >= 2 { // if len(submatchall) >= 2 {
if d, ok := v.Doors[pos]; ok { // if d, ok := v.Doors[pos]; ok {
d.SubPosition = submatchall[1] // d.SubPosition = submatchall[1]
v.Doors[pos] = d // v.Doors[pos] = d
} // }
} // }
} // }
} // }
// parseWindow . // parseWindow .
func (v *Vehicle) parseWindow(prefix, suffix, name string, value any) { // func (v *Vehicle) parseWindow(prefix, suffix, name string, value any) {
re := regexp.MustCompile(`[A-Z][^A-Z]*`) // re := regexp.MustCompile(`[A-Z][^A-Z]*`)
pos := strings.TrimPrefix(name, prefix) // pos := strings.TrimPrefix(name, prefix)
pos = strings.TrimSuffix(pos, suffix) // pos = strings.TrimSuffix(pos, suffix)
submatchall := re.FindAllString(pos, -1) // 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 w, ok := v.Windows[pos]; ok { // if w, ok := v.Windows[pos]; ok {
w.Status = value.(string) // w.Status = value.(string)
w.Updated = time.Now() // w.Updated = time.Now()
v.Windows[pos] = w // v.Windows[pos] = w
} else { // } else {
v.Windows[pos] = Window{ // v.Windows[pos] = Window{
Position: submatchall[0], // Position: submatchall[0],
Status: value.(string), // Status: value.(string),
Updated: time.Now(), // Updated: time.Now(),
} // }
if len(submatchall) >= 2 { // if len(submatchall) >= 2 {
if w, ok := v.Windows[pos]; ok { // if w, ok := v.Windows[pos]; ok {
w.SubPosition = submatchall[1] // w.SubPosition = submatchall[1]
v.Windows[pos] = w // v.Windows[pos] = w
} // }
} // }
} // }
} // }
// parseTirePsi . // parseTirePsi .
func (v *Vehicle) parseTirePsi(prefix, suffix, name string, value any) { // func (v *Vehicle) parseTirePsi(prefix, suffix, name string, value any) {
re := regexp.MustCompile(`[A-Z][^A-Z]*`) // re := regexp.MustCompile(`[A-Z][^A-Z]*`)
pos := strings.TrimPrefix(name, prefix) // pos := strings.TrimPrefix(name, prefix)
pos = strings.TrimSuffix(pos, suffix) // pos = strings.TrimSuffix(pos, suffix)
submatchall := re.FindAllString(pos, -1) // 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 t, ok := v.Tires[pos]; ok { // if t, ok := v.Tires[pos]; ok {
t.PressurePsi = value.(int) // t.PressurePsi = value.(int)
t.Updated = time.Now() // t.Updated = time.Now()
v.Tires[pos] = t // v.Tires[pos] = t
} else { // } else {
v.Tires[pos] = Tire{ // v.Tires[pos] = Tire{
Position: submatchall[0], // Position: submatchall[0],
PressurePsi: value.(int), // PressurePsi: value.(int),
Updated: time.Now(), // Updated: time.Now(),
} // }
if len(submatchall) >= 2 { // if len(submatchall) >= 2 {
if t, ok := v.Tires[pos]; ok { // if t, ok := v.Tires[pos]; ok {
t.SubPosition = submatchall[1] // t.SubPosition = submatchall[1]
v.Tires[pos] = t // v.Tires[pos] = t
} // }
} // }
} // }
} // }
// parseTire . // parseTire .
func (v *Vehicle) parseTire(prefix, suffix, name string, value any) { // func (v *Vehicle) parseTire(prefix, suffix, name string, value any) {
re := regexp.MustCompile(`[A-Z][^A-Z]*`) // re := regexp.MustCompile(`[A-Z][^A-Z]*`)
pos := strings.TrimPrefix(name, prefix) // pos := strings.TrimPrefix(name, prefix)
pos = strings.TrimSuffix(pos, suffix) // pos = strings.TrimSuffix(pos, suffix)
submatchall := re.FindAllString(pos, -1) // 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 t, ok := v.Tires[pos]; ok { // if t, ok := v.Tires[pos]; ok {
t.Pressure = int(value.(float64)) // t.Pressure = int(value.(float64))
t.Updated = time.Now() // t.Updated = time.Now()
v.Tires[pos] = t // v.Tires[pos] = t
} else { // } else {
v.Tires[pos] = Tire{ // v.Tires[pos] = Tire{
Position: submatchall[0], // Position: submatchall[0],
Pressure: int(value.(float64)), // Pressure: int(value.(float64)),
Updated: time.Now(), // Updated: time.Now(),
} // }
if len(submatchall) >= 2 { // if len(submatchall) >= 2 {
if t, ok := v.Tires[pos]; ok { // if t, ok := v.Tires[pos]; ok {
t.SubPosition = submatchall[1] // t.SubPosition = submatchall[1]
v.Tires[pos] = t // v.Tires[pos] = t
} // }
} // }
} // }
} // }
// // getRemoteStartStatus . // // getRemoteStartStatus .
// // Get whether the specified VIN has remote engine start service available. // // Get whether the specified VIN has remote engine start service available.