Updated doors/windows update way
This commit is contained in:
98
vehicle.go
98
vehicle.go
@ -531,6 +531,8 @@ func (v *Vehicle) GetVehicleStatus() {
|
||||
reqURL := MOBILE_API_VERSION + urlToGen(apiURLs["API_VEHICLE_STATUS"], v.getAPIGen())
|
||||
resp := v.client.execute(reqURL, GET, map[string]string{}, "", false)
|
||||
|
||||
v.client.logger.Debug("http request output", "request", "GetVehicleStatus", "body", resp)
|
||||
|
||||
if v.client.isResponseSuccessfull(resp) {
|
||||
respParsed, err := gabs.ParseJSON(resp)
|
||||
if err != nil {
|
||||
@ -571,15 +573,22 @@ func (v *Vehicle) GetVehicleStatus() {
|
||||
fmt.Println(element)
|
||||
}
|
||||
|
||||
door := Door{}
|
||||
door.Position = submatchall[0]
|
||||
newdoor := Door{}
|
||||
newdoor.Position = submatchall[0]
|
||||
if len(submatchall) >= 3 {
|
||||
door.SubPosition = submatchall[1]
|
||||
newdoor.SubPosition = submatchall[1]
|
||||
}
|
||||
|
||||
door.Status = child.Data().(string)
|
||||
door.Updated = time.Now()
|
||||
v.Doors = append(v.Doors, &door)
|
||||
for _, door := range v.Doors {
|
||||
if door.Position == newdoor.Position && door.SubPosition == newdoor.SubPosition {
|
||||
door.Status = child.Data().(string)
|
||||
door.Updated = time.Now()
|
||||
} else {
|
||||
newdoor.Status = child.Data().(string)
|
||||
newdoor.Updated = time.Now()
|
||||
v.Doors = append(v.Doors, &newdoor)
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(key, "door") && strings.HasSuffix(key, "Status") {
|
||||
submatchall := re.FindAllString(key, -1)
|
||||
@ -588,15 +597,22 @@ func (v *Vehicle) GetVehicleStatus() {
|
||||
fmt.Println(element)
|
||||
}
|
||||
|
||||
door := Door{}
|
||||
door.Position = submatchall[0]
|
||||
newdoor := Door{}
|
||||
newdoor.Position = submatchall[0]
|
||||
if len(submatchall) >= 3 {
|
||||
door.SubPosition = submatchall[1]
|
||||
newdoor.SubPosition = submatchall[1]
|
||||
}
|
||||
|
||||
door.Status = child.Data().(string)
|
||||
door.Updated = time.Now()
|
||||
v.Doors = append(v.Doors, &door)
|
||||
for _, door := range v.Doors {
|
||||
if door.Position == newdoor.Position && door.SubPosition == newdoor.SubPosition {
|
||||
door.Status = child.Data().(string)
|
||||
door.Updated = time.Now()
|
||||
} else {
|
||||
newdoor.Status = child.Data().(string)
|
||||
newdoor.Updated = time.Now()
|
||||
v.Doors = append(v.Doors, &newdoor)
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(key, "window") && strings.HasSuffix(key, "Status") {
|
||||
submatchall := re.FindAllString(key, -1)
|
||||
@ -605,15 +621,22 @@ func (v *Vehicle) GetVehicleStatus() {
|
||||
fmt.Println(element)
|
||||
}
|
||||
|
||||
window := Window{}
|
||||
window.Position = submatchall[0]
|
||||
newwindow := Window{}
|
||||
newwindow.Position = submatchall[0]
|
||||
if len(submatchall) >= 3 {
|
||||
window.SubPosition = submatchall[1]
|
||||
newwindow.SubPosition = submatchall[1]
|
||||
}
|
||||
|
||||
window.Status = child.Data().(string)
|
||||
window.Updated = time.Now()
|
||||
v.Windows = append(v.Windows, &window)
|
||||
for _, window := range v.Windows {
|
||||
if window.Position == newwindow.Position && window.SubPosition == newwindow.SubPosition {
|
||||
window.Status = child.Data().(string)
|
||||
window.Updated = time.Now()
|
||||
} else {
|
||||
newwindow.Status = child.Data().(string)
|
||||
newwindow.Updated = time.Now()
|
||||
v.Windows = append(v.Windows, &newwindow)
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(key, "tire") && !strings.HasSuffix(key, "Psi") {
|
||||
v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data())
|
||||
@ -701,15 +724,22 @@ func (v *Vehicle) GetVehicleCondition() {
|
||||
for _, element := range submatchall {
|
||||
fmt.Println(element)
|
||||
}
|
||||
door := Door{}
|
||||
door.Position = submatchall[0]
|
||||
newdoor := Door{}
|
||||
newdoor.Position = submatchall[0]
|
||||
if len(submatchall) >= 3 {
|
||||
door.SubPosition = submatchall[1]
|
||||
newdoor.SubPosition = submatchall[1]
|
||||
}
|
||||
door.Status = child.Data().(string)
|
||||
door.Updated = time.Now()
|
||||
v.Doors = append(v.Doors, &door)
|
||||
|
||||
for _, door := range v.Doors {
|
||||
if door.Position == newdoor.Position && door.SubPosition == newdoor.SubPosition {
|
||||
door.Status = child.Data().(string)
|
||||
door.Updated = time.Now()
|
||||
} else {
|
||||
newdoor.Status = child.Data().(string)
|
||||
newdoor.Updated = time.Now()
|
||||
v.Doors = append(v.Doors, &newdoor)
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(key, "window") && strings.HasSuffix(key, "Status") {
|
||||
submatchall := re.FindAllString(key, -1)
|
||||
@ -717,14 +747,22 @@ func (v *Vehicle) GetVehicleCondition() {
|
||||
for _, element := range submatchall {
|
||||
fmt.Println(element)
|
||||
}
|
||||
window := Window{}
|
||||
window.Position = submatchall[0]
|
||||
newwindow := Window{}
|
||||
newwindow.Position = submatchall[0]
|
||||
if len(submatchall) >= 3 {
|
||||
window.SubPosition = submatchall[1]
|
||||
newwindow.SubPosition = submatchall[1]
|
||||
}
|
||||
|
||||
for _, window := range v.Windows {
|
||||
if window.Position == newwindow.Position && window.SubPosition == newwindow.SubPosition {
|
||||
window.Status = child.Data().(string)
|
||||
window.Updated = time.Now()
|
||||
} else {
|
||||
newwindow.Status = child.Data().(string)
|
||||
newwindow.Updated = time.Now()
|
||||
v.Windows = append(v.Windows, &newwindow)
|
||||
}
|
||||
}
|
||||
window.Status = child.Data().(string)
|
||||
window.Updated = time.Now()
|
||||
v.Windows = append(v.Windows, &window)
|
||||
}
|
||||
if strings.HasPrefix(key, "tire") && !strings.HasSuffix(key, "Unit") {
|
||||
v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data())
|
||||
|
Reference in New Issue
Block a user