Changed the way of parsing parts
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 24s
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 24s
This commit is contained in:
293
vehicle.go
293
vehicle.go
@ -633,16 +633,16 @@ func (v *Vehicle) GetVehicleStatus() {
|
||||
continue
|
||||
} else {
|
||||
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())
|
||||
}
|
||||
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.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, "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") {
|
||||
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
|
||||
} else {
|
||||
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") {
|
||||
v.parseWindow("Window", "Status", 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())
|
||||
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, "Door") && strings.HasSuffix(typeOfS.Field(i).Name, "LockStatus") {
|
||||
// v.parseLock("Door", "LockStatus", typeOfS.Field(i).Name, val.Field(i).Interface())
|
||||
// }
|
||||
@ -790,139 +790,182 @@ func (v *Vehicle) getRemoteOptionsStatus() bool {
|
||||
}
|
||||
|
||||
// parseDoor .
|
||||
func (v *Vehicle) parseDoor(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)
|
||||
func (v *Vehicle) parseParts(name string, value any) {
|
||||
// re := regexp.MustCompile(`[A-Z][^A-Z]*`)
|
||||
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)?`)
|
||||
grps := re.FindStringSubmatch(name)
|
||||
|
||||
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))
|
||||
|
||||
if d, ok := v.Doors[pos]; ok {
|
||||
d.Status = value.(string)
|
||||
d.Updated = time.Now()
|
||||
v.Doors[pos] = d
|
||||
} else {
|
||||
v.Doors[pos] = Door{
|
||||
Position: submatchall[0],
|
||||
Status: value.(string),
|
||||
Updated: time.Now(),
|
||||
switch grps[1] {
|
||||
case "Door", "door":
|
||||
if d, ok := v.Doors[pn]; ok {
|
||||
d.Status = value.(string)
|
||||
d.Updated = time.Now()
|
||||
v.Doors[pn] = d
|
||||
} else {
|
||||
v.Doors[pn] = Door{
|
||||
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 {
|
||||
if d, ok := v.Doors[pos]; ok {
|
||||
d.SubPosition = submatchall[1]
|
||||
v.Doors[pos] = d
|
||||
case "Window", "window":
|
||||
if w, ok := v.Windows[pn]; ok {
|
||||
w.Status = value.(string)
|
||||
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 .
|
||||
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("door lock status", "key", name, "value", value, "number", len(submatchall))
|
||||
// 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("door lock status", "key", name, "value", value, "number", len(submatchall))
|
||||
|
||||
if d, ok := v.Doors[pos]; ok {
|
||||
d.Lock = value.(string)
|
||||
d.Updated = time.Now()
|
||||
v.Doors[pos] = d
|
||||
} else {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if d, ok := v.Doors[pos]; ok {
|
||||
// d.Lock = value.(string)
|
||||
// d.Updated = time.Now()
|
||||
// v.Doors[pos] = d
|
||||
// } else {
|
||||
// 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))
|
||||
// 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))
|
||||
|
||||
if w, ok := v.Windows[pos]; ok {
|
||||
w.Status = value.(string)
|
||||
w.Updated = time.Now()
|
||||
v.Windows[pos] = w
|
||||
} else {
|
||||
v.Windows[pos] = Window{
|
||||
Position: submatchall[0],
|
||||
Status: value.(string),
|
||||
Updated: time.Now(),
|
||||
}
|
||||
if len(submatchall) >= 2 {
|
||||
if w, ok := v.Windows[pos]; ok {
|
||||
w.SubPosition = submatchall[1]
|
||||
v.Windows[pos] = w
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if w, ok := v.Windows[pos]; ok {
|
||||
// w.Status = value.(string)
|
||||
// w.Updated = time.Now()
|
||||
// v.Windows[pos] = w
|
||||
// } else {
|
||||
// v.Windows[pos] = Window{
|
||||
// Position: submatchall[0],
|
||||
// Status: value.(string),
|
||||
// Updated: time.Now(),
|
||||
// }
|
||||
// if len(submatchall) >= 2 {
|
||||
// if w, ok := v.Windows[pos]; ok {
|
||||
// w.SubPosition = submatchall[1]
|
||||
// v.Windows[pos] = w
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// parseTirePsi .
|
||||
func (v *Vehicle) parseTirePsi(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))
|
||||
// func (v *Vehicle) parseTirePsi(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))
|
||||
|
||||
if t, ok := v.Tires[pos]; ok {
|
||||
t.PressurePsi = value.(int)
|
||||
t.Updated = time.Now()
|
||||
v.Tires[pos] = t
|
||||
} else {
|
||||
v.Tires[pos] = Tire{
|
||||
Position: submatchall[0],
|
||||
PressurePsi: value.(int),
|
||||
Updated: time.Now(),
|
||||
}
|
||||
if len(submatchall) >= 2 {
|
||||
if t, ok := v.Tires[pos]; ok {
|
||||
t.SubPosition = submatchall[1]
|
||||
v.Tires[pos] = t
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if t, ok := v.Tires[pos]; ok {
|
||||
// t.PressurePsi = value.(int)
|
||||
// t.Updated = time.Now()
|
||||
// v.Tires[pos] = t
|
||||
// } else {
|
||||
// v.Tires[pos] = Tire{
|
||||
// Position: submatchall[0],
|
||||
// PressurePsi: value.(int),
|
||||
// Updated: time.Now(),
|
||||
// }
|
||||
// if len(submatchall) >= 2 {
|
||||
// if t, ok := v.Tires[pos]; ok {
|
||||
// t.SubPosition = submatchall[1]
|
||||
// v.Tires[pos] = t
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// parseTire .
|
||||
func (v *Vehicle) parseTire(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))
|
||||
// func (v *Vehicle) parseTire(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))
|
||||
|
||||
if t, ok := v.Tires[pos]; ok {
|
||||
t.Pressure = int(value.(float64))
|
||||
t.Updated = time.Now()
|
||||
v.Tires[pos] = t
|
||||
} else {
|
||||
v.Tires[pos] = Tire{
|
||||
Position: submatchall[0],
|
||||
Pressure: int(value.(float64)),
|
||||
Updated: time.Now(),
|
||||
}
|
||||
if len(submatchall) >= 2 {
|
||||
if t, ok := v.Tires[pos]; ok {
|
||||
t.SubPosition = submatchall[1]
|
||||
v.Tires[pos] = t
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if t, ok := v.Tires[pos]; ok {
|
||||
// t.Pressure = int(value.(float64))
|
||||
// t.Updated = time.Now()
|
||||
// v.Tires[pos] = t
|
||||
// } else {
|
||||
// v.Tires[pos] = Tire{
|
||||
// Position: submatchall[0],
|
||||
// Pressure: int(value.(float64)),
|
||||
// Updated: time.Now(),
|
||||
// }
|
||||
// if len(submatchall) >= 2 {
|
||||
// if t, ok := v.Tires[pos]; ok {
|
||||
// t.SubPosition = submatchall[1]
|
||||
// v.Tires[pos] = t
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // getRemoteStartStatus .
|
||||
// // Get whether the specified VIN has remote engine start service available.
|
||||
|
Reference in New Issue
Block a user