From 3b7c350826616ea50f053d65d7ef2bc50583e729 Mon Sep 17 00:00:00 2001 From: Alex Savin Date: Fri, 30 May 2025 12:52:02 -0400 Subject: [PATCH] More changes --- vehicle.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/vehicle.go b/vehicle.go index 328ba9f..33decee 100644 --- a/vehicle.go +++ b/vehicle.go @@ -486,10 +486,10 @@ func (v *Vehicle) GetClimatePresets() { v.client.logger.Debug("subaru climate presets http output", "body", resp) tmp := struct { - Success bool `json:"success"` - ErrorCode string `json:"errorCode"` - DataName string `json:"dataName"` - Data []ClimateProfile `json:"data"` + 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 { @@ -497,8 +497,21 @@ func (v *Vehicle) GetClimatePresets() { } v.client.logger.Debug("subaru climate presets parsed http output", "body", tmp) - if len(tmp.Data) > 0 { - for _, cp := range tmp.Data { + unescapedJSON, err := strconv.Unquote(string(tmp.Data)) + if err != nil { + fmt.Println("Error unquoting:", err) + return + } + + var cProfiles []ClimateProfile + err = json.Unmarshal([]byte(unescapedJSON), &cProfiles) + if err != nil { + v.client.logger.Error("error while parsing json", "request", "GetClimatePresets", "error", err.Error()) + } + v.client.logger.Debug("subaru climate presets parsed http output", "body", cProfiles) + + if len(cProfiles) > 0 { + for _, cp := range cProfiles { if v.isEV() && cp.VehicleType == "phev" { if _, ok := v.ClimateProfiles[cp.PresetType+cp.Name]; ok { v.ClimateProfiles[cp.PresetType+cp.Name] = cp