Alphan version of the climate presets parsing
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 22s

This commit is contained in:
2025-05-30 16:43:36 -04:00
parent d6937621e6
commit 28eedd8ead

View File

@ -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())
}