diff --git a/client.go b/client.go index 0a9c115..e91d2b8 100644 --- a/client.go +++ b/client.go @@ -127,11 +127,7 @@ func (c *Client) SelectVehicle(vin string) VehicleData { return VehicleData{} } - // resp := c.execute(reqURL, GET, params, "", false) - // logger.Debugf("SELECT VEHICLE OUTPUT >> %v\n", string([]byte(resp))) - // ERRORS - // {"success":false,"errorCode":"vehicleNotInAccount","dataName":null,"data":null} // """Select active vehicle for accounts with multiple VINs.""" // params = {"vin": vin, "_": int(time.time())} @@ -225,19 +221,16 @@ func (c *Client) GetVehicleByVIN(vin string) *Vehicle { // func getRemoteStartStatus() {} // func getSafetyStatus() {} // func getSubscriptionStatus() {} -// func getAPIGen() {} // func getClimateData() {} // func saveClimateSettings() {} -// func getVehicleName() {} -// func fetch() {} // Exec method executes a Client instance with the API URL func (c *Client) execute(requestUrl string, method string, params map[string]string, pollingUrl string, j bool, attempts ...int) []byte { - defer timeTrack("[TIMETRK] Executing Get Request") + defer timeTrack("[TIMETRK] Executing HTTP Request") var resp *resty.Response // GET Requests - if method == "GET" { + if method == GET { resp, _ = c.httpClient. R(). SetQueryParams(params). @@ -245,7 +238,7 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str } // POST Requests - if method == "POST" { + if method == POST { if j { // POST > JSON Body resp, _ = c.httpClient. R(). @@ -273,7 +266,6 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str if err != nil { c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error()) } - // {"success":false,"errorCode":"404-soa-unableToParseResponseBody","dataName":"errorResponse","data":{"errorLabel":"404-soa-unableToParseResponseBody","errorDescription":null}} if pollingUrl != "" { switch { @@ -296,9 +288,18 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str } } } else { + if r.DataName == "errorResponse" { + // {"success":false,"errorCode":"404-soa-unableToParseResponseBody","dataName":"errorResponse","data":{"errorLabel":"404-soa-unableToParseResponseBody","errorDescription":null}} + // {"success":false,"errorCode":"vehicleNotInAccount","dataName":null,"data":null} + var er ErrorResponse + err := json.Unmarshal(r.Data, &er) + if err != nil { + c.logger.Error("error while parsing json", "request", "errorResponse", "error", err.Error()) + } + c.logger.Error("request is not successfull", "request", "execute", "method", method, "url", requestUrl, "error", err.Error()) + } c.logger.Error("request is not successfull", "request", "execute", "method", method, "url", requestUrl, "error", err.Error()) } - return resBytes } diff --git a/example/example.go b/example/example.go index c792bc2..8add41c 100644 --- a/example/example.go +++ b/example/example.go @@ -10,7 +10,6 @@ import ( ) func main() { - var err error configFile, err := os.ReadFile("config.yaml") @@ -38,8 +37,8 @@ func main() { // fmt.Printf("GEN #1: %+v\n\n", subaru1.getAPIGen()) // ABS_MIL ACCS AHBL_MIL ATF_MIL AWD_MIL BSD BSDRCT_MIL CEL_MIL EBD_MIL EOL_MIL EPAS_MIL EPB_MIL ESS_MIL EYESIGHT ISS_MIL OPL_MIL PANPM-TUIRWAOC PWAAADWWAP RAB_MIL RCC REARBRK RES RESCC RHSF RPOI RPOIA RTGU RVFS SRH_MIL SRS_MIL TEL_MIL TIF_35 TIR_33 TLD TPMS_MIL VALET VDC_MIL WASH_MIL g3 - subaru := ms.GetVehicleByVIN("4S4BTGPD0P3199198") - subaru.GetLocation(true) + outback := ms.GetVehicleByVIN("4S4BTGPD0P3199198") + // subaru.GetLocation(true) // subaru.EngineStart() fmt.Printf("SUBARU #1 (Vehicle Status):\n") @@ -52,11 +51,6 @@ func main() { // fmt.Printf("SUBARU #2: %+v\n", subaru) // subaru.GetVehicleHealth() // subaru.GetFeaturesList() - - // subaru.LightsStart() - // time.Sleep(10 * time.Second) - // subaru.LightsStop() - // subaru := mysubaru.GetVehicles()[0] // fmt.Printf("SUBARU: %+v\n", subaru) @@ -73,12 +67,6 @@ func main() { // subaru.GetClimatePresets() // subaru.GetClimateUserPresets() - // subaru.LightsStart() - // time.Sleep(15 * time.Second) - // subaru.LightsStop() - - // subaru.listDevices() - // subaru.GetVehicleStatus() // subaru.GetClimateSettings() @@ -91,10 +79,6 @@ func main() { // time.Sleep(20 * time.Second) // subaru.Lock() - // subaru.LightsStart() - // time.Sleep(15 * time.Second) - // subaru.LightsStop() - // subaru.GetLocation() - fmt.Printf("SUBARU: %+v\n", subaru) + fmt.Printf("SUBARU: %+v\n", outback) } diff --git a/mysubaru.go b/mysubaru.go index 569aa31..05aa705 100644 --- a/mysubaru.go +++ b/mysubaru.go @@ -170,14 +170,14 @@ type VehicleStatus struct { AvgFuelConsumptionMpg float64 `json:"avgFuelConsumptionMpg"` // + 18.4 AvgFuelConsumptionLitersPer100Kilometers float64 `json:"avgFuelConsumptionLitersPer100Kilometers"` // + 12.8 RemainingFuelPercent int `json:"remainingFuelPercent,string"` // + "82" - TirePressureFrontLeft int `json:"tirePressureFrontLeft,string"` // + "2275" - TirePressureFrontRight int `json:"tirePressureFrontRight,string"` // + "2344" - TirePressureRearLeft int `json:"tirePressureRearLeft,string"` // + "2413" - TirePressureRearRight int `json:"tirePressureRearRight,string"` // + "2344" - TirePressureFrontLeftPsi int `json:"tirePressureFrontLeftPsi,string"` // + "33" - TirePressureFrontRightPsi int `json:"tirePressureFrontRightPsi,string"` // + "34" - TirePressureRearLeftPsi int `json:"tirePressureRearLeftPsi,string"` // + "35" - TirePressureRearRightPsi int `json:"tirePressureRearRightPsi,string"` // + "34" + TirePressureFrontLeft int `json:"tirePressureFrontLeft,string,omitempty"` // + "2275" + TirePressureFrontRight int `json:"tirePressureFrontRight,string,omitempty"` // + "2344" + TirePressureRearLeft int `json:"tirePressureRearLeft,string,omitempty"` // + "2413" + TirePressureRearRight int `json:"tirePressureRearRight,string,omitempty"` // + "2344" + TirePressureFrontLeftPsi int `json:"tirePressureFrontLeftPsi,string,omitempty"` // + "33" + TirePressureFrontRightPsi int `json:"tirePressureFrontRightPsi,string,omitempty"` // + "34" + TirePressureRearLeftPsi int `json:"tirePressureRearLeftPsi,string,omitempty"` // + "35" + TirePressureRearRightPsi int `json:"tirePressureRearRightPsi,string,omitempty"` // + "34" TyreStatusFrontLeft string `json:"tyreStatusFrontLeft"` // + "UNKNOWN" TyreStatusFrontRight string `json:"tyreStatusFrontRight"` // + "UNKNOWN" TyreStatusRearLeft string `json:"tyreStatusRearLeft"` // + "UNKNOWN" @@ -188,55 +188,55 @@ type VehicleStatus struct { EvDistanceToEmptyByStateMiles int `json:"evDistanceToEmptyByStateMiles,omitempty"` // + null EvDistanceToEmptyByStateKilometers int `json:"evDistanceToEmptyByStateKilometers,omitempty"` // + null VehicleStateType string `json:"vehicleStateType"` // + "IGNITION_OFF | IGNITION_ON" - WindowFrontLeftStatus string `json:"windowFrontLeftStatus"` // + "CLOSE" - WindowFrontRightStatus string `json:"windowFrontRightStatus"` // + "CLOSE" - WindowRearLeftStatus string `json:"windowRearLeftStatus"` // + "CLOSE" - WindowRearRightStatus string `json:"windowRearRightStatus"` // + "CLOSE" - WindowSunroofStatus string `json:"windowSunroofStatus"` // + "CLOSE" - DoorBootPosition string `json:"doorBootPosition"` // CLOSED - DoorEngineHoodPosition string `json:"doorEngineHoodPosition"` // CLOSED - DoorFrontLeftPosition string `json:"doorFrontLeftPosition"` // CLOSED - DoorFrontRightPosition string `json:"doorFrontRightPosition"` // CLOSED - DoorRearLeftPosition string `json:"doorRearLeftPosition"` // CLOSED - DoorRearRightPosition string `json:"doorRearRightPosition"` // CLOSED - DoorBootLockStatus string `json:"doorBootLockStatus"` // LOCKED - DoorFrontLeftLockStatus string `json:"doorFrontLeftLockStatus"` // LOCKED - DoorFrontRightLockStatus string `json:"doorFrontRightLockStatus"` // LOCKED - DoorRearLeftLockStatus string `json:"doorRearLeftLockStatus"` // LOCKED - DoorRearRightLockStatus string `json:"doorRearRightLockStatus"` // LOCKED + WindowFrontLeftStatus string `json:"windowFrontLeftStatus"` // CLOSE | VENTED | OPEN + WindowFrontRightStatus string `json:"windowFrontRightStatus"` // CLOSE | VENTED | OPEN + WindowRearLeftStatus string `json:"windowRearLeftStatus"` // CLOSE | VENTED | OPEN + WindowRearRightStatus string `json:"windowRearRightStatus"` // CLOSE | VENTED | OPEN + WindowSunroofStatus string `json:"windowSunroofStatus"` // CLOSE | VENTED | OPEN + DoorBootPosition string `json:"doorBootPosition"` // CLOSED | OPEN + DoorEngineHoodPosition string `json:"doorEngineHoodPosition"` // CLOSED | OPEN + DoorFrontLeftPosition string `json:"doorFrontLeftPosition"` // CLOSED | OPEN + DoorFrontRightPosition string `json:"doorFrontRightPosition"` // CLOSED | OPEN + DoorRearLeftPosition string `json:"doorRearLeftPosition"` // CLOSED | OPEN + DoorRearRightPosition string `json:"doorRearRightPosition"` // CLOSED | OPEN + DoorBootLockStatus string `json:"doorBootLockStatus"` // LOCKED | UNLOCKED + DoorFrontLeftLockStatus string `json:"doorFrontLeftLockStatus"` // LOCKED | UNLOCKED + DoorFrontRightLockStatus string `json:"doorFrontRightLockStatus"` // LOCKED | UNLOCKED + DoorRearLeftLockStatus string `json:"doorRearLeftLockStatus"` // LOCKED | UNLOCKED + DoorRearRightLockStatus string `json:"doorRearRightLockStatus"` // LOCKED | UNLOCKED } // VehicleCondition . // "dataName":"remoteServiceStatus" // "remoteServiceType":"condition" type VehicleCondition struct { - VehicleStateType string `json:"vehicleStateType"` // "IGNITION_OFF", - AvgFuelConsumption float64 `json:"avgFuelConsumption,omitempty"` // null, - AvgFuelConsumptionUnit string `json:"avgFuelConsumptionUnit"` // "MPG", - DistanceToEmptyFuel int `json:"distanceToEmptyFuel,omitempty"` // null, - DistanceToEmptyFuelUnit string `json:"distanceToEmptyFuelUnit"` // "MILES", - RemainingFuelPercent int `json:"remainingFuelPercent"` // "66", - Odometer int `json:"odometer"` // 92, - OdometerUnit string `json:"odometerUnit"` // "MILES", - TirePressureFrontLeft float64 `json:"tirePressureFrontLeft,omitempty"` // null, - TirePressureFrontLeftUnit string `json:"tirePressureFrontLeftUnit"` // "PSI", - TirePressureFrontRight float64 `json:"tirePressureFrontRight,omitempty"` // null, + VehicleStateType string `json:"vehicleStateType"` // "IGNITION_OFF | IGNITION_ON" + AvgFuelConsumption float64 `json:"avgFuelConsumption,omitempty"` // null | 18.4 + AvgFuelConsumptionUnit string `json:"avgFuelConsumptionUnit"` // "MPG" + DistanceToEmptyFuel int `json:"distanceToEmptyFuel,omitempty"` // null | 160 + DistanceToEmptyFuelUnit string `json:"distanceToEmptyFuelUnit"` // "MILES" + RemainingFuelPercent int `json:"remainingFuelPercent,string"` // "66" + Odometer int `json:"odometer"` // 92 + OdometerUnit string `json:"odometerUnit"` // "MILES" + TirePressureFrontLeft float64 `json:"tirePressureFrontLeft,omitempty"` // null | 36 + TirePressureFrontLeftUnit string `json:"tirePressureFrontLeftUnit"` // "PSI" + TirePressureFrontRight float64 `json:"tirePressureFrontRight,omitempty"` // null | 36 TirePressureFrontRightUnit string `json:"tirePressureFrontRightUnit"` // "PSI", - TirePressureRearLeft float64 `json:"tirePressureRearLeft,omitempty"` // null, - TirePressureRearLeftUnit string `json:"tirePressureRearLeftUnit"` // "PSI", - TirePressureRearRight float64 `json:"tirePressureRearRight,omitempty"` // null, - TirePressureRearRightUnit string `json:"tirePressureRearRightUnit"` // "PSI", - DoorBootPosition string `json:"doorBootPosition"` // "CLOSED", - DoorEngineHoodPosition string `json:"doorEngineHoodPosition"` // "CLOSED", - DoorFrontLeftPosition string `json:"doorFrontLeftPosition"` // "CLOSED", - DoorFrontRightPosition string `json:"doorFrontRightPosition"` // "CLOSED", - DoorRearLeftPosition string `json:"doorRearLeftPosition"` // "CLOSED", - DoorRearRightPosition string `json:"doorRearRightPosition"` // "CLOSED" - WindowFrontLeftStatus string `json:"windowFrontLeftStatus"` // "CLOSE", - WindowFrontRightStatus string `json:"windowFrontRightStatus"` // "CLOSE", - WindowRearLeftStatus string `json:"windowRearLeftStatus"` // "CLOSE", - WindowRearRightStatus string `json:"windowRearRightStatus"` // "CLOSE", - WindowSunroofStatus string `json:"windowSunroofStatus"` // "CLOSE", + TirePressureRearLeft float64 `json:"tirePressureRearLeft,omitempty"` // null | 36 + TirePressureRearLeftUnit string `json:"tirePressureRearLeftUnit"` // "PSI" + TirePressureRearRight float64 `json:"tirePressureRearRight,omitempty"` // null | 36 + TirePressureRearRightUnit string `json:"tirePressureRearRightUnit"` // "PSI" + DoorBootPosition string `json:"doorBootPosition"` // "CLOSED | OPEN" + DoorEngineHoodPosition string `json:"doorEngineHoodPosition"` // "CLOSED | OPEN" + DoorFrontLeftPosition string `json:"doorFrontLeftPosition"` // "CLOSED | OPEN" + DoorFrontRightPosition string `json:"doorFrontRightPosition"` // "CLOSED | OPEN" + DoorRearLeftPosition string `json:"doorRearLeftPosition"` // "CLOSED | OPEN" + DoorRearRightPosition string `json:"doorRearRightPosition"` // "CLOSED | OPEN" + WindowFrontLeftStatus string `json:"windowFrontLeftStatus"` // "CLOSE | VENTED | OPEN" + WindowFrontRightStatus string `json:"windowFrontRightStatus"` // "CLOSE | VENTED | OPEN" + WindowRearLeftStatus string `json:"windowRearLeftStatus"` // "CLOSE | VENTED | OPEN" + WindowRearRightStatus string `json:"windowRearRightStatus"` // "CLOSE | VENTED | OPEN" + WindowSunroofStatus string `json:"windowSunroofStatus"` // "CLOSE | VENTED | OPEN" EvDistanceToEmpty int `json:"evDistanceToEmpty,omitempty"` // null, EvDistanceToEmptyUnit string `json:"evDistanceToEmptyUnit,omitempty"` // null, EvChargerStateType string `json:"evChargerStateType,omitempty"` // null, @@ -302,10 +302,10 @@ type VehicleHealth struct { LastUpdatedDate int64 `json:"lastUpdatedDate"` } type VehicleHealthItem struct { - B2cCode string `json:"b2cCode"` - FeatureCode string `json:"featureCode"` - IsTrouble bool `json:"isTrouble"` - OnDaiID int `json:"onDaiId"` - OnDates []string `json:"onDates"` - WarningCode int `json:"warningCode"` + B2cCode string `json:"b2cCode"` + FeatureCode string `json:"featureCode"` + IsTrouble bool `json:"isTrouble"` + OnDaiID int `json:"onDaiId"` + OnDates []int64 `json:"onDates,omitempty"` + WarningCode int `json:"warningCode"` } diff --git a/vehicle.go b/vehicle.go index 384099f..f5398a1 100644 --- a/vehicle.go +++ b/vehicle.go @@ -458,10 +458,10 @@ func (v *Vehicle) GetClimatePresets() { if len(cProfiles) > 0 { for _, cp := range cProfiles { if v.isEV() && cp.VehicleType == "phev" { - if _, ok := v.ClimateProfiles[cp.PresetType+cp.Name]; ok { + if _, ok := v.ClimateProfiles[cp.PresetType+strings.TrimSpace(cp.Name)]; ok { v.ClimateProfiles[cp.PresetType+cp.Name] = cp } else { - if _, ok := v.ClimateProfiles[cp.PresetType+cp.Name]; ok { + if _, ok := v.ClimateProfiles[cp.PresetType+strings.TrimSpace(cp.Name)]; ok { v.ClimateProfiles[cp.PresetType+cp.Name] = cp } else { v.ClimateProfiles[cp.PresetType+cp.Name] = cp @@ -469,10 +469,10 @@ func (v *Vehicle) GetClimatePresets() { } } if !v.isEV() && cp.VehicleType == "gas" { - if _, ok := v.ClimateProfiles[cp.PresetType+cp.Name]; ok { + if _, ok := v.ClimateProfiles[cp.PresetType+strings.TrimSpace(cp.Name)]; ok { v.ClimateProfiles[cp.PresetType+cp.Name] = cp } else { - if _, ok := v.ClimateProfiles[cp.PresetType+cp.Name]; ok { + if _, ok := v.ClimateProfiles[cp.PresetType+strings.TrimSpace(cp.Name)]; ok { v.ClimateProfiles[cp.PresetType+cp.Name] = cp } else { v.ClimateProfiles[cp.PresetType+cp.Name] = cp @@ -481,7 +481,7 @@ func (v *Vehicle) GetClimatePresets() { } } } else { - v.client.logger.Debug("didn't find any climate quick presets") + v.client.logger.Debug("didn't find any climate presets") } v.Updated = time.Now() } else { @@ -509,16 +509,16 @@ func (v *Vehicle) GetClimateQuickPresets() { re2 := regexp.MustCompile(`\\`) result = re2.ReplaceAllString(result, `"`) // \u0022 - var cProfile ClimateProfile - err = json.Unmarshal([]byte(result), &cProfile) + var cp ClimateProfile + err = json.Unmarshal([]byte(result), &cp) if err != nil { v.client.logger.Error("error while parsing climate quick presets json", "request", "GetClimateQuickPresets", "error", err.Error()) } - if _, ok := v.ClimateProfiles[cProfile.PresetType+cProfile.Name]; ok { - v.ClimateProfiles[cProfile.PresetType+cProfile.Name] = cProfile + if _, ok := v.ClimateProfiles["quick"+cp.PresetType+strings.TrimSpace(cp.Name)]; ok { + v.ClimateProfiles["quick"+cp.PresetType+strings.TrimSpace(cp.Name)] = cp } else { - v.ClimateProfiles[cProfile.PresetType+cProfile.Name] = cProfile + v.ClimateProfiles["quick"+cp.PresetType+strings.TrimSpace(cp.Name)] = cp } v.Updated = time.Now() } else { @@ -552,13 +552,13 @@ func (v *Vehicle) GetClimateUserPresets() { if len(cProfiles) > 0 { for _, cp := range cProfiles { - if _, ok := v.ClimateProfiles[cp.PresetType+cp.Name]; ok { - v.ClimateProfiles[cp.PresetType+cp.Name] = cp + if _, ok := v.ClimateProfiles[cp.PresetType+strings.TrimSpace(cp.Name)]; ok { + v.ClimateProfiles[cp.PresetType+strings.TrimSpace(cp.Name)] = cp } else { - if _, ok := v.ClimateProfiles[cp.PresetType+cp.Name]; ok { - v.ClimateProfiles[cp.PresetType+cp.Name] = cp + if _, ok := v.ClimateProfiles[cp.PresetType+strings.TrimSpace(cp.Name)]; ok { + v.ClimateProfiles[cp.PresetType+strings.TrimSpace(cp.Name)] = cp } else { - v.ClimateProfiles[cp.PresetType+cp.Name] = cp + v.ClimateProfiles[cp.PresetType+strings.TrimSpace(cp.Name)] = cp } } }