diff --git a/vehicle.go b/vehicle.go index e64cc19..f78ecbf 100644 --- a/vehicle.go +++ b/vehicle.go @@ -473,7 +473,11 @@ func (v *Vehicle) GetClimateQuickPresets() { } } -// GetClimatePresets . +// GetClimatePresets connects to the MySubaru API to download available climate presets. +// It first attempts to establish a connection with the MySubaru API. +// If successful and climate presets are found for the user's vehicle, +// it downloads them. If no presets are available, or if the connection fails, +// appropriate handling should be implemented within the function. func (v *Vehicle) GetClimatePresets() { if v.getRemoteOptionsStatus() { v.selectVehicle() @@ -483,10 +487,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 any `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 { @@ -494,6 +498,12 @@ func (v *Vehicle) GetClimatePresets() { } v.client.logger.Debug("subaru climate presets parsed http output", "body", tmp) + var cProfiles []ClimateProfile + err = json.Unmarshal([]byte(tmp.Data), &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) // respParsed, err := gabs.ParseJSON([]byte(resp)) // if err != nil { // v.client.logger.Error("error while parsing json", "request", "GetClimatePresets", "error", err.Error())