Refactor session validation and enhance error handling in vehicle commands
Some checks failed
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Failing after 24s

This commit is contained in:
2025-07-08 15:34:07 -04:00
parent aec4b8435b
commit 30bd0bde44
3 changed files with 116 additions and 92 deletions

View File

@ -437,8 +437,8 @@ func (c *Client) parseResponse(b []byte) (Response, bool) {
}
// ValidateSession checks if the current session is valid by making a request to the vehicle status API.
func (c *Client) ValidateSession() bool {
reqURL := MOBILE_API_VERSION + apiURLs["API_VEHICLE_STATUS"]
func (c *Client) validateSession() bool {
reqURL := MOBILE_API_VERSION + apiURLs["API_VALIDATE_SESSION"]
resp, err := c.execute(GET, reqURL, map[string]string{}, false)
if err != nil {
c.logger.Error("error while executing validateSession request", "request", "validateSession", "error", err.Error())
@ -446,9 +446,35 @@ func (c *Client) ValidateSession() bool {
}
c.logger.Debug("http request output", "request", "validateSession", "body", resp)
if resp.Success {
_, err := c.SelectVehicle(c.currentVin)
if err != nil {
c.logger.Error("error while selecting vehicle", "request", "validateSession", "error", err.Error())
return false
}
}
if !resp.Success {
_, err := c.auth()
if err != nil {
c.logger.Error("error while re-authenticating", "request", "validateSession", "error", err.Error())
return false
}
_, err = c.SelectVehicle(c.currentVin)
if err != nil {
c.logger.Error("error while selecting vehicle", "request", "validateSession", "error", err.Error())
return false
}
}
return true
}
// isPINRequired .
// Return if a vehicle with an active remote service subscription exists.
// func (v *Vehicle) isPINRequired() bool {
// return v.getRemoteOptionsStatus()
// }
// func isPINRequired() {}
// func getEVStatus() {}
// func getRemoteOptionsStatus() {}