Some changes
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 26s
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 26s
This commit is contained in:
@ -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
|
||||||
}
|
}
|
||||||
|
240
vehicle.go
240
vehicle.go
@ -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 {
|
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())
|
||||||
}
|
}
|
||||||
|
|
||||||
re := regexp.MustCompile(`[A-Z][^A-Z]*`)
|
if r.Success {
|
||||||
|
var sr ServiceRequest
|
||||||
|
err = json.Unmarshal(r.Data, &sr)
|
||||||
|
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)
|
||||||
|
|
||||||
for key, child := range respParsed.S("data").S("result").ChildrenMap() {
|
var vc VehicleCondition
|
||||||
fmt.Printf("key: %v, value: %v\n", key, child.Data())
|
err = json.Unmarshal(sr.Result, &vc)
|
||||||
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 err != nil {
|
||||||
continue
|
v.client.logger.Error("error while parsing json", "request", "GetClimatePresets", "error", err.Error())
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(key, "door") && strings.HasSuffix(key, "Position") {
|
v.client.logger.Debug("http request output", "request", "GetVehicleStatus", "body", resp)
|
||||||
pos := strings.TrimPrefix(key, "door")
|
|
||||||
pos = strings.TrimSuffix(pos, "Position")
|
|
||||||
submatchall := re.FindAllString(pos, -1)
|
|
||||||
v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
|
|
||||||
|
|
||||||
if door, ok := v.Doors[pos]; ok {
|
val := reflect.ValueOf(vc)
|
||||||
door.Status = child.Data().(string)
|
typeOfS := val.Type()
|
||||||
door.Updated = time.Now()
|
|
||||||
} else {
|
|
||||||
door.Status = child.Data().(string)
|
|
||||||
door.Updated = time.Now()
|
|
||||||
v.Doors[pos] = Door{
|
|
||||||
Position: submatchall[0],
|
|
||||||
Status: child.Data().(string),
|
|
||||||
Updated: time.Now(),
|
|
||||||
}
|
|
||||||
if len(submatchall) >= 2 {
|
|
||||||
if d, ok := v.Doors[pos]; ok {
|
|
||||||
d.SubPosition = submatchall[1]
|
|
||||||
v.Doors[pos] = d
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(key, "door") && strings.HasSuffix(key, "LockStatus") {
|
|
||||||
pos := strings.TrimPrefix(key, "door")
|
|
||||||
pos = strings.TrimSuffix(pos, "LockStatus")
|
|
||||||
submatchall := re.FindAllString(pos, -1)
|
|
||||||
v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
|
|
||||||
|
|
||||||
if door, ok := v.Doors[pos]; ok {
|
for i := 0; i < val.NumField(); i++ {
|
||||||
door.Lock = child.Data().(string)
|
fmt.Printf("Field: %s, Value: %v, Type: %v\n", typeOfS.Field(i).Name, val.Field(i).Interface(), val.Field(i).Type())
|
||||||
door.Updated = time.Now()
|
|
||||||
} else {
|
|
||||||
door.Lock = child.Data().(string)
|
|
||||||
door.Updated = time.Now()
|
|
||||||
v.Doors[pos] = Door{
|
|
||||||
Position: submatchall[0],
|
|
||||||
Lock: child.Data().(string),
|
|
||||||
Updated: time.Now(),
|
|
||||||
}
|
}
|
||||||
if len(submatchall) >= 2 {
|
|
||||||
if d, ok := v.Doors[pos]; ok {
|
|
||||||
d.SubPosition = submatchall[1]
|
|
||||||
v.Doors[pos] = d
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(key, "window") && strings.HasSuffix(key, "Status") {
|
|
||||||
pos := strings.TrimPrefix(key, "window")
|
|
||||||
pos = strings.TrimSuffix(pos, "Status")
|
|
||||||
submatchall := re.FindAllString(pos, -1)
|
|
||||||
v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
|
|
||||||
|
|
||||||
if window, ok := v.Windows[pos]; ok {
|
// re := regexp.MustCompile(`[A-Z][^A-Z]*`)
|
||||||
window.Status = child.Data().(string)
|
|
||||||
window.Updated = time.Now()
|
|
||||||
} else {
|
|
||||||
window.Status = child.Data().(string)
|
|
||||||
window.Updated = time.Now()
|
|
||||||
v.Windows[pos] = Window{
|
|
||||||
Position: submatchall[0],
|
|
||||||
Status: child.Data().(string),
|
|
||||||
Updated: time.Now(),
|
|
||||||
}
|
|
||||||
if len(submatchall) >= 2 {
|
|
||||||
if w, ok := v.Windows[pos]; ok {
|
|
||||||
w.SubPosition = submatchall[1]
|
|
||||||
v.Windows[pos] = w
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(key, "tirePressure") && strings.HasSuffix(key, "Psi") {
|
|
||||||
pos := strings.TrimPrefix(key, "tirePressure")
|
|
||||||
pos = strings.TrimSuffix(pos, "Psi")
|
|
||||||
submatchall := re.FindAllString(pos, -1)
|
|
||||||
v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
|
|
||||||
|
|
||||||
if tire, ok := v.Tires[pos]; ok {
|
// for key, child := range respParsed.S("data").S("result").ChildrenMap() {
|
||||||
tire.PressurePsi = child.Data().(string)
|
// fmt.Printf("key: %v, value: %v\n", key, child.Data())
|
||||||
tire.Updated = time.Now()
|
// if child.Data() == "NOT_EQUIPPED" || child.Data() == "UNKNOWN" || child.Data() == "16383" || child.Data() == "65535" || child.Data() == "None" || child.Data() == "-64.0" || child.Data() == nil {
|
||||||
} else {
|
// continue
|
||||||
tire.PressurePsi = child.Data().(string)
|
// }
|
||||||
tire.Updated = time.Now()
|
// if strings.HasPrefix(key, "door") && strings.HasSuffix(key, "Position") {
|
||||||
v.Tires[pos] = Tire{
|
// pos := strings.TrimPrefix(key, "door")
|
||||||
Position: submatchall[0],
|
// pos = strings.TrimSuffix(pos, "Position")
|
||||||
PressurePsi: child.Data().(string),
|
// submatchall := re.FindAllString(pos, -1)
|
||||||
Updated: time.Now(),
|
// v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
|
||||||
}
|
|
||||||
if len(submatchall) >= 2 {
|
// if door, ok := v.Doors[pos]; ok {
|
||||||
if t, ok := v.Tires[pos]; ok {
|
// door.Status = child.Data().(string)
|
||||||
t.SubPosition = submatchall[1]
|
// door.Updated = time.Now()
|
||||||
v.Tires[pos] = t
|
// } else {
|
||||||
}
|
// door.Status = child.Data().(string)
|
||||||
}
|
// door.Updated = time.Now()
|
||||||
}
|
// v.Doors[pos] = Door{
|
||||||
}
|
// Position: submatchall[0],
|
||||||
v.Updated = time.Now()
|
// Status: child.Data().(string),
|
||||||
}
|
// Updated: time.Now(),
|
||||||
|
// }
|
||||||
|
// if len(submatchall) >= 2 {
|
||||||
|
// if d, ok := v.Doors[pos]; ok {
|
||||||
|
// d.SubPosition = submatchall[1]
|
||||||
|
// v.Doors[pos] = d
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if strings.HasPrefix(key, "door") && strings.HasSuffix(key, "LockStatus") {
|
||||||
|
// pos := strings.TrimPrefix(key, "door")
|
||||||
|
// pos = strings.TrimSuffix(pos, "LockStatus")
|
||||||
|
// submatchall := re.FindAllString(pos, -1)
|
||||||
|
// v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
|
||||||
|
|
||||||
|
// if door, ok := v.Doors[pos]; ok {
|
||||||
|
// door.Lock = child.Data().(string)
|
||||||
|
// door.Updated = time.Now()
|
||||||
|
// } else {
|
||||||
|
// door.Lock = child.Data().(string)
|
||||||
|
// door.Updated = time.Now()
|
||||||
|
// v.Doors[pos] = Door{
|
||||||
|
// Position: submatchall[0],
|
||||||
|
// Lock: child.Data().(string),
|
||||||
|
// Updated: time.Now(),
|
||||||
|
// }
|
||||||
|
// if len(submatchall) >= 2 {
|
||||||
|
// if d, ok := v.Doors[pos]; ok {
|
||||||
|
// d.SubPosition = submatchall[1]
|
||||||
|
// v.Doors[pos] = d
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if strings.HasPrefix(key, "window") && strings.HasSuffix(key, "Status") {
|
||||||
|
// pos := strings.TrimPrefix(key, "window")
|
||||||
|
// pos = strings.TrimSuffix(pos, "Status")
|
||||||
|
// submatchall := re.FindAllString(pos, -1)
|
||||||
|
// v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
|
||||||
|
|
||||||
|
// if window, ok := v.Windows[pos]; ok {
|
||||||
|
// window.Status = child.Data().(string)
|
||||||
|
// window.Updated = time.Now()
|
||||||
|
// } else {
|
||||||
|
// window.Status = child.Data().(string)
|
||||||
|
// window.Updated = time.Now()
|
||||||
|
// v.Windows[pos] = Window{
|
||||||
|
// Position: submatchall[0],
|
||||||
|
// Status: child.Data().(string),
|
||||||
|
// Updated: time.Now(),
|
||||||
|
// }
|
||||||
|
// if len(submatchall) >= 2 {
|
||||||
|
// if w, ok := v.Windows[pos]; ok {
|
||||||
|
// w.SubPosition = submatchall[1]
|
||||||
|
// v.Windows[pos] = w
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if strings.HasPrefix(key, "tirePressure") && strings.HasSuffix(key, "Psi") {
|
||||||
|
// pos := strings.TrimPrefix(key, "tirePressure")
|
||||||
|
// pos = strings.TrimSuffix(pos, "Psi")
|
||||||
|
// submatchall := re.FindAllString(pos, -1)
|
||||||
|
// v.client.logger.Debug("VEHICLE COND", "key", key, "data", child.Data(), "number", len(submatchall))
|
||||||
|
|
||||||
|
// if tire, ok := v.Tires[pos]; ok {
|
||||||
|
// tire.PressurePsi = child.Data().(string)
|
||||||
|
// tire.Updated = time.Now()
|
||||||
|
// } else {
|
||||||
|
// tire.PressurePsi = child.Data().(string)
|
||||||
|
// tire.Updated = time.Now()
|
||||||
|
// v.Tires[pos] = Tire{
|
||||||
|
// Position: submatchall[0],
|
||||||
|
// PressurePsi: child.Data().(string),
|
||||||
|
// Updated: time.Now(),
|
||||||
|
// }
|
||||||
|
// if len(submatchall) >= 2 {
|
||||||
|
// if t, ok := v.Tires[pos]; ok {
|
||||||
|
// t.SubPosition = submatchall[1]
|
||||||
|
// v.Tires[pos] = t
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// 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())
|
||||||
|
Reference in New Issue
Block a user