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

This commit is contained in:
2025-05-29 23:54:16 -04:00
parent 2ab1070bce
commit 68866189fb

View File

@ -482,49 +482,49 @@ func (v *Vehicle) GetClimatePresets() {
v.client.logger.Debug("subaru climate presets http output", "body", resp) v.client.logger.Debug("subaru climate presets http output", "body", resp)
tmp1 := strings.ReplaceAll(string(resp), "\\\\\\\"", "\"") respParsed, err := gabs.ParseJSON([]byte(resp))
v.client.logger.Debug("subaru climate presets after trimming #1", "body", tmp1)
tmp2 := strings.ReplaceAll(tmp1, `}\",\"{`, `},{`)
v.client.logger.Debug("subaru climate presets after trimming #2", "body", tmp2)
tmp3 := strings.ReplaceAll(tmp2, `[\"{`, `[{`)
v.client.logger.Debug("subaru climate presets after trimming #3", "body", tmp3)
tmp4 := strings.ReplaceAll(tmp3, ` }\"]`, `}]`)
v.client.logger.Debug("subaru climate presets after trimming #4", "body", tmp4)
tmp5 := strings.ReplaceAll(tmp4, `\"`, `"`)
v.client.logger.Debug("subaru climate presets after trimming", "body", tmp5)
respParsed, err := gabs.ParseJSON([]byte(tmp5))
if err != nil { if err != nil {
v.client.logger.Error("error while parsing json", "request", "GetClimatePresets", "error", err.Error()) v.client.logger.Error("error while parsing json", "request", "GetClimatePresets", "error", err.Error())
} }
v.client.logger.Debug("subaru climate presets parsed http output", "body", respParsed) v.client.logger.Debug("subaru climate presets parsed http output", "body", respParsed)
// ONLY FOR THAT REQUEST BECAUSE OF API SENDS BACK ESCAPING DATA IN DATA FIELD // tmp1 := strings.ReplaceAll(string(resp), "\\\\"", "\"")
data, ok := respParsed.Path("data").Data().(string) // v.client.logger.Debug("subaru climate presets after trimming #1", "body", tmp1)
if !ok { // tmp2 := strings.ReplaceAll(tmp1, `}\",\"{`, `},{`)
v.client.logger.Error("error while parsing data json", "request", "GetClimatePresets", "error", err.Error()) // v.client.logger.Debug("subaru climate presets after trimming #2", "body", tmp2)
} // tmp3 := strings.ReplaceAll(tmp2, `[\"{`, `[{`)
// v.client.logger.Debug("subaru climate presets after trimming #3", "body", tmp3)
// tmp4 := strings.ReplaceAll(tmp3, ` }\"]`, `}]`)
// v.client.logger.Debug("subaru climate presets after trimming #4", "body", tmp4)
// tmp5 := strings.ReplaceAll(tmp4, `\"`, `"`)
var cProfiles []ClimateProfile v.client.logger.Debug("subaru climate presets before trimming", "body", respParsed)
err = json.Unmarshal([]byte(data), &cProfiles)
if err != nil {
v.client.logger.Error("error while parsing climate subaru presets json", "request", "GetClimatePresets", "error", err.Error())
}
v.client.logger.Debug("climate subaru presets", "data", data)
if len(cProfiles) > 0 { // // ONLY FOR THAT REQUEST BECAUSE OF API SENDS BACK ESCAPING DATA IN DATA FIELD
for _, cp := range cProfiles { // data, ok := respParsed.Path("data").Data().(string)
if _, ok := v.ClimateProfiles[cp.PresetType+cp.Name]; ok { // if !ok {
v.ClimateProfiles[cp.PresetType+cp.Name] = cp // v.client.logger.Error("error while parsing data json", "request", "GetClimatePresets", "error", err.Error())
} else { // }
v.ClimateProfiles[cp.PresetType+cp.Name] = cp
} // var cProfiles []ClimateProfile
} // err = json.Unmarshal([]byte(data), &cProfiles)
} else { // if err != nil {
v.client.logger.Debug("didn't find any climate subaru presets") // v.client.logger.Error("error while parsing climate subaru presets json", "request", "GetClimatePresets", "error", err.Error())
} // }
v.Updated = time.Now() // v.client.logger.Debug("climate subaru presets", "data", data)
// if len(cProfiles) > 0 {
// for _, cp := range cProfiles {
// if _, ok := v.ClimateProfiles[cp.PresetType+cp.Name]; ok {
// v.ClimateProfiles[cp.PresetType+cp.Name] = cp
// } else {
// v.ClimateProfiles[cp.PresetType+cp.Name] = cp
// }
// }
// } else {
// v.client.logger.Debug("didn't find any climate subaru presets")
// }
// v.Updated = time.Now()
} else { } else {
v.client.logger.Error("active STARLINK Security Plus subscription required") v.client.logger.Error("active STARLINK Security Plus subscription required")
} }