Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remote auto seat climate request #237

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions pkg/proxy/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ func ExtractCommandAction(ctx context.Context, command string, params RequestPar

return func(v *vehicle.Vehicle) error { return v.SetSeatHeater(ctx, setting) }, nil
case "remote_auto_seat_climate_request":
level, seat, err := params.settingForAutoSeatPosition()
seat, enabled, err := params.settingForAutoSeatPosition()
if err != nil {
return nil, err
}
return func(v *vehicle.Vehicle) error { return v.SetSeatCooler(ctx, level, seat) }, nil
return func(v *vehicle.Vehicle) error {
return v.AutoSeatAndClimate(ctx, []vehicle.SeatPosition{seat}, enabled)
}, nil
case "remote_steering_wheel_heater_request":
on, err := params.getBool("on", true)
if err != nil {
Expand Down Expand Up @@ -471,11 +473,15 @@ func (p RequestParameters) settingForCoolerSeatPosition() (vehicle.Level, vehicl
return vehicle.Level(level - 1), seat, nil
}

// Note: The API uses 0-3
func (p RequestParameters) settingForAutoSeatPosition() (vehicle.Level, vehicle.SeatPosition, error) {
func (p RequestParameters) settingForAutoSeatPosition() (vehicle.SeatPosition, bool, error) {
position, err := p.getNumber("auto_seat_position", true)
if err != nil {
return 0, 0, err
return 0, false, err
}

enabled, err := p.getBool("auto_climate_on", true)
if err != nil {
return 0, false, err
}

var seat vehicle.SeatPosition
Expand All @@ -488,12 +494,7 @@ func (p RequestParameters) settingForAutoSeatPosition() (vehicle.Level, vehicle.
seat = vehicle.SeatUnknown
}

level, err := p.getNumber("seat_position", true)
if err != nil {
return 0, 0, err
}

return vehicle.Level(level - 1), seat, nil
return seat, enabled, nil
}

func missingParamError(key string) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (p *Proxy) loadVehicleAndCommandFromRequest(ctx context.Context, acct *acco
log.Debug("Executing %s on %s", command, vin)
if req.Method != http.MethodPost {
writeJSONError(w, http.StatusMethodNotAllowed, nil)
return nil, nil, fmt.Errorf("Wrong http method")
return nil, nil, fmt.Errorf("wrong http method")
}

commandToExecuteFunc, err := extractCommandAction(ctx, req, command)
Expand Down
Loading