Compare commits

...

2 Commits

Author SHA1 Message Date
439d4dc15b Changed fmt to logger
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 23s
2025-05-28 14:04:26 -04:00
5fe6cc55f5 Updated doors/windows update way 2025-05-28 14:04:06 -04:00
2 changed files with 71 additions and 33 deletions

View File

@ -251,10 +251,10 @@ func New(config *config.Config) (*Client, error) {
client.registerDevice()
}
// TODO
fmt.Printf("Parcing cars: %d\n", len(respParsed.Path("data.vehicles").Children()))
// TODO: create a list of the car with currently present data
client.logger.Debug("parcing cars assigned to the account", "quantity", len(respParsed.Path("data.vehicles").Children()))
for _, vehicle := range respParsed.Path("data.vehicles").Children() {
fmt.Printf("CAR: %s\n", vehicle.Path("vin").Data().(string))
client.logger.Debug("parsing car", "vin", vehicle.Path("vin").Data().(string))
client.listOfVins = append(client.listOfVins, vehicle.Path("vin").Data().(string))
}
client.currentVin = respParsed.Path("data.vehicles.0.vin").Data().(string)

View File

@ -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]
}
for _, door := range v.Doors {
if door.Position == newdoor.Position && door.SubPosition == newdoor.SubPosition {
door.Status = child.Data().(string)
door.Updated = time.Now()
v.Doors = append(v.Doors, &door)
} 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]
}
for _, door := range v.Doors {
if door.Position == newdoor.Position && door.SubPosition == newdoor.SubPosition {
door.Status = child.Data().(string)
door.Updated = time.Now()
v.Doors = append(v.Doors, &door)
} 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]
}
for _, window := range v.Windows {
if window.Position == newwindow.Position && window.SubPosition == newwindow.SubPosition {
window.Status = child.Data().(string)
window.Updated = time.Now()
v.Windows = append(v.Windows, &window)
} 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]
}
for _, door := range v.Doors {
if door.Position == newdoor.Position && door.SubPosition == newdoor.SubPosition {
door.Status = child.Data().(string)
door.Updated = time.Now()
v.Doors = append(v.Doors, &door)
} 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()
v.Windows = append(v.Windows, &window)
} else {
newwindow.Status = child.Data().(string)
newwindow.Updated = time.Now()
v.Windows = append(v.Windows, &newwindow)
}
}
}
if strings.HasPrefix(key, "tire") && !strings.HasSuffix(key, "Unit") {
v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data())