Refactor vehicle climate control methods to improve parameter handling and add new climate preset updates
Some checks failed
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Failing after 24s

This commit is contained in:
2025-07-10 08:36:31 -04:00
parent ebe98e685a
commit 89b3d44d82
3 changed files with 153 additions and 50 deletions

View File

@ -201,24 +201,34 @@ func (v *Vehicle) Unlock() (chan string, error) {
// EngineStart
// Sends a command to start engine and set climate control.
func (v *Vehicle) EngineStart() (chan string, error) {
// TODO: Get Quick Climate Preset from the Currect Car
func (v *Vehicle) EngineStart(run, delay int, horn bool) (chan string, error) {
if run < 1 || run > 10 {
return nil, errors.New("run time must be between 1 and 10 minutes")
}
var startConfig string
if v.EV {
startConfig = START_CONFIG_DEFAULT_EV
} else {
startConfig = START_CONFIG_DEFAULT_RES
}
params := map[string]string{
"delay": "0",
"delay": strconv.Itoa(delay),
"vin": v.Vin,
"pin": v.client.credentials.PIN,
"horn": "true",
"climateSettings": "climateSettings", // climateSettings
"climateZoneFrontTemp": "65", // 60-86
"climateZoneFrontAirMode": "WINDOW", // FEET_FACE_BALANCED | FEET_WINDOW | WINDOW | FEET
"climateZoneFrontAirVolume": "6", // 1-7
"heatedSeatFrontLeft": "OFF", // OFF | LOW_HEAT | MEDIUM_HEAT | HIGH_HEAT | low_cool | medium_cool | high_cool
"heatedSeatFrontRight": "OFF", // ---//---
"heatedRearWindowActive": "true", // boolean
"outerAirCirculation": "outsideAir", // outsideAir | recirculation
"airConditionOn": "false", // boolean
"runTimeMinutes": "10", // 1-10
"startConfiguration": START_CONFIG_DEFAULT_RES, // START_ENGINE_ALLOW_KEY_IN_IGNITION | ONLY FOR PHEV > START_CLIMATE_CONTROL_ONLY_ALLOW_KEY_IN_IGNITION
"horn": strconv.FormatBool(horn),
"climateSettings": "climateSettings", // climateSettings
"climateZoneFrontTemp": "65", // 60-86
"climateZoneFrontAirMode": "WINDOW", // FEET_FACE_BALANCED | FEET_WINDOW | WINDOW | FEET
"climateZoneFrontAirVolume": "6", // 1-7
"heatedSeatFrontLeft": "OFF", // OFF | LOW_HEAT | MEDIUM_HEAT | HIGH_HEAT | LOW_COOL | MEDIUM_COOL | HIGH_COOL
"heatedSeatFrontRight": "OFF", // ---//---
"heatedRearWindowActive": "true", // boolean
"outerAirCirculation": "outsideAir", // outsideAir | recirculation
"airConditionOn": "false", // boolean
"runTimeMinutes": strconv.Itoa(run), // 1-10
"startConfiguration": startConfig, // START_ENGINE_ALLOW_KEY_IN_IGNITION | ONLY FOR PHEV > START_CLIMATE_CONTROL_ONLY_ALLOW_KEY_IN_IGNITION
}
reqUrl := MOBILE_API_VERSION + apiURLs["API_G2_REMOTE_ENGINE_START"]
pollingUrl := MOBILE_API_VERSION + apiURLs["API_REMOTE_SVC_STATUS"]
@ -500,6 +510,47 @@ func (v *Vehicle) GetClimateQuickPresets() error {
return nil
}
// UpdateClimateQuickPresets
// Updates the quick climate presets by fetching them from the MySubaru API.
func (v *Vehicle) UpdateClimateQuickPresets() error {
if !v.getRemoteOptionsStatus() {
v.client.logger.Error(APP_ERRORS["SUBSCRIBTION_REQUIRED"])
return errors.New(APP_ERRORS["SUBSCRIBTION_REQUIRED"])
}
// Validate session before executing the request
if !v.client.validateSession() {
v.client.logger.Error(APP_ERRORS["SESSION_EXPIRED"])
return errors.New(APP_ERRORS["SESSION_EXPIRED"])
}
if v.Vin != (v.client).currentVin {
v.selectVehicle()
}
params := map[string]string{
"presetType": "userPreset",
"name": "Cooling",
"runTimeMinutes": "10",
"climateZoneFrontTemp": "65",
"climateZoneFrontAirMode": "FEET_FACE_BALANCED",
"climateZoneFrontAirVolume": "7",
"outerAirCirculation": "outsideAir",
"heatedRearWindowActive": "false",
"heatedSeatFrontLeft": "HIGH_COOL",
"airConditionOn": "false",
"startConfiguration": "START_ENGINE_ALLOW_KEY_IN_IGNITION",
// "canEdit": "true",
// "disabled": "false",
}
reqUrl := MOBILE_API_VERSION + apiURLs["API_G2_SAVE_RES_QUICK_START_SETTINGS"]
resp, _ := v.client.execute(POST, reqUrl, params, false)
v.client.logger.Debug("http request output", "request", "UpdateClimateUserPresets", "body", resp)
return nil
}
// GetClimateUserPresets
func (v *Vehicle) GetClimateUserPresets() error {
if !v.getRemoteOptionsStatus() {
@ -552,6 +603,46 @@ func (v *Vehicle) GetClimateUserPresets() error {
return nil
}
// UpdateClimateUserPresets
// Updates the user's climate presets by fetching them from the MySubaru API.
func (v *Vehicle) UpdateClimateUserPresets() error {
if !v.getRemoteOptionsStatus() {
v.client.logger.Error(APP_ERRORS["SUBSCRIBTION_REQUIRED"])
return errors.New(APP_ERRORS["SUBSCRIBTION_REQUIRED"])
}
// Validate session before executing the request
if !v.client.validateSession() {
v.client.logger.Error(APP_ERRORS["SESSION_EXPIRED"])
return errors.New(APP_ERRORS["SESSION_EXPIRED"])
}
if v.Vin != (v.client).currentVin {
v.selectVehicle()
}
params := map[string]string{
"presetType": "userPreset",
"name": "Cooling",
"runTimeMinutes": "10",
"climateZoneFrontTemp": "65",
"climateZoneFrontAirMode": "FEET_FACE_BALANCED",
"climateZoneFrontAirVolume": "7",
"outerAirCirculation": "outsideAir",
"heatedRearWindowActive": "false",
"heatedSeatFrontLeft": "HIGH_COOL",
"airConditionOn": "false",
"startConfiguration": "START_ENGINE_ALLOW_KEY_IN_IGNITION",
// "canEdit": "true",
// "disabled": "false",
}
reqUrl := MOBILE_API_VERSION + apiURLs["API_G2_SAVE_RES_SETTINGS"]
resp, _ := v.client.execute(POST, reqUrl, params, false)
v.client.logger.Debug("http request output", "request", "UpdateClimateUserPresets", "body", resp)
return nil
}
// GetVehicleStatus .
func (v *Vehicle) GetVehicleStatus() error {
if !v.getRemoteOptionsStatus() {