Climate Presets
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 23s
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 23s
This commit is contained in:
121
vehicle.go
121
vehicle.go
@ -429,57 +429,6 @@ func (v *Vehicle) GetLocation(force bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetClimateQuickPresets
|
||||
// Used while user uses "quick start engine" button in the app
|
||||
func (v *Vehicle) GetClimateQuickPresets() {
|
||||
if v.getRemoteOptionsStatus() {
|
||||
v.selectVehicle()
|
||||
reqURL := MOBILE_API_VERSION + apiURLs["API_G2_FETCH_RES_QUICK_START_SETTINGS"]
|
||||
resp := v.client.execute(reqURL, GET, map[string]string{}, "", false)
|
||||
|
||||
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 json", "request", "GetClimatePresets", "error", err.Error())
|
||||
}
|
||||
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(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", result)
|
||||
|
||||
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 quick presets")
|
||||
}
|
||||
v.Updated = time.Now()
|
||||
} else {
|
||||
v.client.logger.Error("active STARLINK Security Plus subscription required")
|
||||
}
|
||||
}
|
||||
|
||||
// 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,
|
||||
@ -490,7 +439,6 @@ func (v *Vehicle) GetClimatePresets() {
|
||||
v.selectVehicle()
|
||||
reqURL := MOBILE_API_VERSION + apiURLs["API_G2_FETCH_RES_SUBARU_PRESETS"]
|
||||
resp := v.client.execute(reqURL, GET, map[string]string{}, "", false)
|
||||
v.client.logger.Debug("subaru climate presets http output", "body", resp)
|
||||
|
||||
tmp := struct {
|
||||
Success bool `json:"success"`
|
||||
@ -502,21 +450,17 @@ func (v *Vehicle) GetClimatePresets() {
|
||||
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", 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(result), &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 {
|
||||
@ -552,13 +496,59 @@ func (v *Vehicle) GetClimatePresets() {
|
||||
}
|
||||
}
|
||||
|
||||
// GetClimateUserPresets .
|
||||
func (v *Vehicle) GetClimateUserPresets() {
|
||||
// GetClimateQuickPresets
|
||||
// Used while user uses "quick start engine" button in the app
|
||||
func (v *Vehicle) GetClimateQuickPresets() {
|
||||
if v.getRemoteOptionsStatus() {
|
||||
v.selectVehicle()
|
||||
reqURL := MOBILE_API_VERSION + apiURLs["API_G2_FETCH_RES_USER_PRESETS"]
|
||||
reqURL := MOBILE_API_VERSION + apiURLs["API_G2_FETCH_RES_QUICK_START_SETTINGS"]
|
||||
resp := v.client.execute(reqURL, GET, map[string]string{}, "", false)
|
||||
|
||||
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 json", "request", "GetClimatePresets", "error", err.Error())
|
||||
}
|
||||
|
||||
re1 := regexp.MustCompile(`\"`)
|
||||
result := re1.ReplaceAllString(string(tmp.Data), "")
|
||||
re2 := regexp.MustCompile(`\\`)
|
||||
result = re2.ReplaceAllString(result, `"`) // \u0022
|
||||
|
||||
var cProfiles []ClimateProfile
|
||||
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())
|
||||
}
|
||||
|
||||
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 quick presets")
|
||||
}
|
||||
v.Updated = time.Now()
|
||||
} else {
|
||||
v.client.logger.Error("active STARLINK Security Plus subscription required")
|
||||
}
|
||||
}
|
||||
|
||||
// GetClimateUserPresets .
|
||||
func (v *Vehicle) GetClimateUserPresets() {
|
||||
if v.getRemoteOptionsStatus() {
|
||||
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("subaru climate presets http output", "body", resp)
|
||||
|
||||
tmp := struct {
|
||||
Success bool `json:"success"`
|
||||
@ -570,21 +560,17 @@ func (v *Vehicle) GetClimateUserPresets() {
|
||||
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", 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(result), &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 {
|
||||
@ -602,13 +588,6 @@ func (v *Vehicle) GetClimateUserPresets() {
|
||||
v.client.logger.Debug("didn't find any climate quick presets")
|
||||
}
|
||||
v.Updated = time.Now()
|
||||
// TODO: Separate EV and CONVETIONAL Climate Profiles
|
||||
// if v.isEV() && climateProfile.VehicleType == "phev" {
|
||||
// v.ClimateProfiles = append(v.ClimateProfiles, climateProfile)
|
||||
// }
|
||||
// if !v.isEV() && climateProfile.VehicleType == "gas" {
|
||||
// v.ClimateProfiles = append(v.ClimateProfiles, climateProfile)
|
||||
// }
|
||||
} else {
|
||||
v.client.logger.Error("active STARLINK Security Plus subscription required")
|
||||
}
|
||||
|
Reference in New Issue
Block a user