diff --git a/vehicle.go b/vehicle.go index e8ded39..9d44d8a 100644 --- a/vehicle.go +++ b/vehicle.go @@ -437,24 +437,31 @@ func (v *Vehicle) GetClimateQuickPresets() { reqURL := MOBILE_API_VERSION + apiURLs["API_G2_FETCH_RES_QUICK_START_SETTINGS"] resp := v.client.execute(reqURL, GET, map[string]string{}, "", false) - respParsed, err := gabs.ParseJSON(resp) + tmp := struct { + Success bool `json:"success"` + ErrorCode string `json:"errorCode"` + DataName string `json:"dataName"` + Data json.RawMessage `json:"data"` + }{} + err := json.Unmarshal(resp, &tmp) if err != nil { - v.client.logger.Error("error while parsing http output json", "request", "GetClimateQuickPresets", "error", err.Error()) + v.client.logger.Error("error while parsing json", "request", "GetClimatePresets", "error", err.Error()) } - v.client.logger.Debug("quick climate presets parsed http output", "body", respParsed) + v.client.logger.Debug("subaru climate presets parsed http output", "body", string(tmp.Data)) - // ONLY FOR THAT REQUEST BECAUSE OF API SENDS BACK ESCAPING DATA IN DATA FIELD - data, ok := respParsed.Path("data").Data().(string) - if !ok { - v.client.logger.Error("error while parsing data json", "request", "GetClimateQuickPresets", "error", err.Error()) - } + re1 := regexp.MustCompile(`\"`) + result := re1.ReplaceAllString(string(tmp.Data), "") + v.client.logger.Debug("subaru climate presets trimmed http output #1", "body", result) + re2 := regexp.MustCompile(`\\`) + result = re2.ReplaceAllString(result, `"`) // \u0022 + v.client.logger.Debug("subaru climate presets trimmed http output #2", "body", result) var cProfiles []ClimateProfile - err = json.Unmarshal([]byte(data), &cProfiles) + err = json.Unmarshal([]byte(result), &cProfiles) if err != nil { v.client.logger.Error("error while parsing climate quick presets json", "request", "GetClimateQuickPresets", "error", err.Error()) } - v.client.logger.Debug("climate quick presets", "data", data) + v.client.logger.Debug("climate quick presets", "data", result) if len(cProfiles) > 0 { for _, cp := range cProfiles { @@ -551,8 +558,7 @@ func (v *Vehicle) GetClimateUserPresets() { v.selectVehicle() reqURL := MOBILE_API_VERSION + apiURLs["API_G2_FETCH_RES_USER_PRESETS"] resp := v.client.execute(reqURL, GET, map[string]string{}, "", false) - - v.client.logger.Debug("user climate presets parsed http output", "body", resp) + v.client.logger.Debug("subaru climate presets http output", "body", resp) tmp := struct { Success bool `json:"success"` @@ -566,8 +572,15 @@ func (v *Vehicle) GetClimateUserPresets() { } v.client.logger.Debug("subaru climate presets parsed http output", "body", string(tmp.Data)) + re1 := regexp.MustCompile(`\"`) + result := re1.ReplaceAllString(string(tmp.Data), "") + v.client.logger.Debug("subaru climate presets trimmed http output #1", "body", result) + re2 := regexp.MustCompile(`\\`) + result = re2.ReplaceAllString(result, `"`) // \u0022 + v.client.logger.Debug("subaru climate presets trimmed http output #2", "body", result) + var cProfiles []ClimateProfile - err = json.Unmarshal([]byte(tmp.Data), &cProfiles) + err = json.Unmarshal([]byte(result), &cProfiles) if err != nil { v.client.logger.Error("error while parsing json", "request", "GetClimatePresets", "error", err.Error()) }