Some changes
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 26s

This commit is contained in:
2025-05-31 20:55:25 -04:00
parent d3c2badfcb
commit d66d529fa9
2 changed files with 137 additions and 111 deletions

View File

@ -3,8 +3,6 @@ package mysubaru
import ( import (
"encoding/json" "encoding/json"
"time" "time"
"github.com/Jeffail/gabs/v2"
) )
// Response . // Response .
@ -262,7 +260,7 @@ type ServiceRequest struct {
RemoteServiceState string `json:"remoteServiceState"` // started | finished | stopping RemoteServiceState string `json:"remoteServiceState"` // started | finished | stopping
SubState *string `json:"subState,omitempty"` // null SubState *string `json:"subState,omitempty"` // null
ErrorCode *string `json:"errorCode,omitempty"` // null:null ErrorCode *string `json:"errorCode,omitempty"` // null:null
Result *gabs.Container `json:"result,omitempty"` // null Result json.RawMessage `json:"result,omitempty"` // null
UpdateTime *time.Time `json:"updateTime,omitempty"` // timestamp UpdateTime *time.Time `json:"updateTime,omitempty"` // timestamp
Vin string `json:"vin"` // 4S4BTGND8L3137058 Vin string `json:"vin"` // 4S4BTGND8L3137058
} }

View File

@ -790,121 +790,143 @@ func (v *Vehicle) GetVehicleCondition() {
resp := v.client.execute(reqURL, GET, map[string]string{}, "", false) resp := v.client.execute(reqURL, GET, map[string]string{}, "", false)
v.client.logger.Debug("http request output", "request", "GetVehicleCondition", "body", resp) v.client.logger.Debug("http request output", "request", "GetVehicleCondition", "body", resp)
if v.client.isResponseSuccessfull(resp) { var r Response
respParsed, err := gabs.ParseJSON(resp) err := json.Unmarshal(resp, &r)
if err != nil {
v.client.logger.Error("error while parsing json", "request", "GetClimatePresets", "error", err.Error())
}
if r.Success {
var sr ServiceRequest
err = json.Unmarshal(r.Data, &sr)
if err != nil { if err != nil {
v.client.logger.Error("error while parsing json", "request", "GetVehicleCondition", "error", err.Error()) v.client.logger.Error("error while parsing json", "request", "GetClimatePresets", "error", err.Error())
}
v.client.logger.Debug("http request output", "request", "GetVehicleStatus", "body", resp)
var vc VehicleCondition
err = json.Unmarshal(sr.Result, &vc)
if err != nil {
v.client.logger.Error("error while parsing json", "request", "GetClimatePresets", "error", err.Error())
}
v.client.logger.Debug("http request output", "request", "GetVehicleStatus", "body", resp)
val := reflect.ValueOf(vc)
typeOfS := val.Type()
for i := 0; i < val.NumField(); i++ {
fmt.Printf("Field: %s, Value: %v, Type: %v\n", typeOfS.Field(i).Name, val.Field(i).Interface(), val.Field(i).Type())
} }
re := regexp.MustCompile(`[A-Z][^A-Z]*`) // re := regexp.MustCompile(`[A-Z][^A-Z]*`)
for key, child := range respParsed.S("data").S("result").ChildrenMap() { // for key, child := range respParsed.S("data").S("result").ChildrenMap() {
fmt.Printf("key: %v, value: %v\n", key, child.Data()) // fmt.Printf("key: %v, value: %v\n", key, child.Data())
if child.Data() == "NOT_EQUIPPED" || child.Data() == "UNKNOWN" || child.Data() == "16383" || child.Data() == "65535" || child.Data() == "None" || child.Data() == "-64.0" || child.Data() == nil { // if child.Data() == "NOT_EQUIPPED" || child.Data() == "UNKNOWN" || child.Data() == "16383" || child.Data() == "65535" || child.Data() == "None" || child.Data() == "-64.0" || child.Data() == nil {
continue // continue
} // }
if strings.HasPrefix(key, "door") && strings.HasSuffix(key, "Position") { // if strings.HasPrefix(key, "door") && strings.HasSuffix(key, "Position") {
pos := strings.TrimPrefix(key, "door") // pos := strings.TrimPrefix(key, "door")
pos = strings.TrimSuffix(pos, "Position") // pos = strings.TrimSuffix(pos, "Position")
submatchall := re.FindAllString(pos, -1) // submatchall := re.FindAllString(pos, -1)
v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall)) // v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
if door, ok := v.Doors[pos]; ok { // if door, ok := v.Doors[pos]; ok {
door.Status = child.Data().(string) // door.Status = child.Data().(string)
door.Updated = time.Now() // door.Updated = time.Now()
} else { // } else {
door.Status = child.Data().(string) // door.Status = child.Data().(string)
door.Updated = time.Now() // door.Updated = time.Now()
v.Doors[pos] = Door{ // v.Doors[pos] = Door{
Position: submatchall[0], // Position: submatchall[0],
Status: child.Data().(string), // Status: child.Data().(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
} // }
} // }
} // }
} // }
if strings.HasPrefix(key, "door") && strings.HasSuffix(key, "LockStatus") { // if strings.HasPrefix(key, "door") && strings.HasSuffix(key, "LockStatus") {
pos := strings.TrimPrefix(key, "door") // pos := strings.TrimPrefix(key, "door")
pos = strings.TrimSuffix(pos, "LockStatus") // pos = strings.TrimSuffix(pos, "LockStatus")
submatchall := re.FindAllString(pos, -1) // submatchall := re.FindAllString(pos, -1)
v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall)) // v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
if door, ok := v.Doors[pos]; ok { // if door, ok := v.Doors[pos]; ok {
door.Lock = child.Data().(string) // door.Lock = child.Data().(string)
door.Updated = time.Now() // door.Updated = time.Now()
} else { // } else {
door.Lock = child.Data().(string) // door.Lock = child.Data().(string)
door.Updated = time.Now() // door.Updated = time.Now()
v.Doors[pos] = Door{ // v.Doors[pos] = Door{
Position: submatchall[0], // Position: submatchall[0],
Lock: child.Data().(string), // Lock: child.Data().(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
} // }
} // }
} // }
} // }
if strings.HasPrefix(key, "window") && strings.HasSuffix(key, "Status") { // if strings.HasPrefix(key, "window") && strings.HasSuffix(key, "Status") {
pos := strings.TrimPrefix(key, "window") // pos := strings.TrimPrefix(key, "window")
pos = strings.TrimSuffix(pos, "Status") // pos = strings.TrimSuffix(pos, "Status")
submatchall := re.FindAllString(pos, -1) // submatchall := re.FindAllString(pos, -1)
v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall)) // v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
if window, ok := v.Windows[pos]; ok { // if window, ok := v.Windows[pos]; ok {
window.Status = child.Data().(string) // window.Status = child.Data().(string)
window.Updated = time.Now() // window.Updated = time.Now()
} else { // } else {
window.Status = child.Data().(string) // window.Status = child.Data().(string)
window.Updated = time.Now() // window.Updated = time.Now()
v.Windows[pos] = Window{ // v.Windows[pos] = Window{
Position: submatchall[0], // Position: submatchall[0],
Status: child.Data().(string), // Status: child.Data().(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
} // }
} // }
} // }
} // }
if strings.HasPrefix(key, "tirePressure") && strings.HasSuffix(key, "Psi") { // if strings.HasPrefix(key, "tirePressure") && strings.HasSuffix(key, "Psi") {
pos := strings.TrimPrefix(key, "tirePressure") // pos := strings.TrimPrefix(key, "tirePressure")
pos = strings.TrimSuffix(pos, "Psi") // pos = strings.TrimSuffix(pos, "Psi")
submatchall := re.FindAllString(pos, -1) // submatchall := re.FindAllString(pos, -1)
v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall)) // v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
if tire, ok := v.Tires[pos]; ok { // if tire, ok := v.Tires[pos]; ok {
tire.PressurePsi = child.Data().(string) // tire.PressurePsi = child.Data().(string)
tire.Updated = time.Now() // tire.Updated = time.Now()
} else { // } else {
tire.PressurePsi = child.Data().(string) // tire.PressurePsi = child.Data().(string)
tire.Updated = time.Now() // tire.Updated = time.Now()
v.Tires[pos] = Tire{ // v.Tires[pos] = Tire{
Position: submatchall[0], // Position: submatchall[0],
PressurePsi: child.Data().(string), // PressurePsi: child.Data().(string),
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
} // }
} // }
} // }
} // }
v.Updated = time.Now() // v.Updated = time.Now()
} // }
} }
// VEHICLE_STATE_TYPE >> IGNITION_OFF // VEHICLE_STATE_TYPE >> IGNITION_OFF
@ -932,7 +954,13 @@ func (v *Vehicle) GetVehicleHealth() {
resp := v.client.execute(reqURL, GET, params, "", false) resp := v.client.execute(reqURL, GET, params, "", false)
v.client.logger.Debug("http request output", "request", "GetVehicleHealth", "body", resp) v.client.logger.Debug("http request output", "request", "GetVehicleHealth", "body", resp)
if v.client.isResponseSuccessfull(resp) { var r Response
err := json.Unmarshal(resp, &r)
if err != nil {
v.client.logger.Error("error while parsing json", "request", "GetVehicleHealth", "error", err.Error())
}
if r.Success {
_, err := gabs.ParseJSON(resp) _, err := gabs.ParseJSON(resp)
if err != nil { if err != nil {
v.client.logger.Error("error while parsing json", "request", "GetVehicleHealth", "error", err.Error()) v.client.logger.Error("error while parsing json", "request", "GetVehicleHealth", "error", err.Error())