Ensure channel closure in LightsStart, LightsStop, and GetLocation methods; improve error handling in executeServiceRequest
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 27s
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 27s
This commit is contained in:
14
vehicle.go
14
vehicle.go
@ -339,7 +339,7 @@ func (v *Vehicle) LightsStart() (chan string, error) {
|
|||||||
}
|
}
|
||||||
ch := make(chan string)
|
ch := make(chan string)
|
||||||
go func() {
|
go func() {
|
||||||
// defer close(ch)
|
defer close(ch)
|
||||||
v.executeServiceRequest(params, reqUrl, pollingUrl, ch, 1)
|
v.executeServiceRequest(params, reqUrl, pollingUrl, ch, 1)
|
||||||
}()
|
}()
|
||||||
return ch, nil
|
return ch, nil
|
||||||
@ -364,7 +364,7 @@ func (v *Vehicle) LightsStop() (chan string, error) {
|
|||||||
}
|
}
|
||||||
ch := make(chan string)
|
ch := make(chan string)
|
||||||
go func() {
|
go func() {
|
||||||
// defer close(ch)
|
defer close(ch)
|
||||||
v.executeServiceRequest(params, reqUrl, pollingUrl, ch, 1)
|
v.executeServiceRequest(params, reqUrl, pollingUrl, ch, 1)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -475,7 +475,7 @@ func (v *Vehicle) GetLocation(force bool) (chan string, error) {
|
|||||||
|
|
||||||
ch := make(chan string)
|
ch := make(chan string)
|
||||||
go func() {
|
go func() {
|
||||||
// defer close(ch)
|
defer close(ch)
|
||||||
v.executeServiceRequest(params, reqUrl, pollingUrl, ch, 1)
|
v.executeServiceRequest(params, reqUrl, pollingUrl, ch, 1)
|
||||||
}()
|
}()
|
||||||
return ch, nil
|
return ch, nil
|
||||||
@ -516,33 +516,31 @@ func (v *Vehicle) executeServiceRequest(params map[string]string, reqUrl, pollin
|
|||||||
// dataName field has the list of the states [ remoteServiceStatus | errorResponse ]
|
// dataName field has the list of the states [ remoteServiceStatus | errorResponse ]
|
||||||
if resp.DataName == "remoteServiceStatus" {
|
if resp.DataName == "remoteServiceStatus" {
|
||||||
if sr, ok := v.parseServiceRequest([]byte(resp.Data)); ok {
|
if sr, ok := v.parseServiceRequest([]byte(resp.Data)); ok {
|
||||||
|
ch <- sr.RemoteServiceState
|
||||||
switch sr.RemoteServiceState {
|
switch sr.RemoteServiceState {
|
||||||
|
|
||||||
case "finished":
|
case "finished":
|
||||||
// Finished RemoteServiceState Service Request does not include Service Request ID
|
// Finished RemoteServiceState Service Request does not include Service Request ID
|
||||||
v.client.logger.Debug("Remote service request completed successfully")
|
v.client.logger.Debug("Remote service request completed successfully")
|
||||||
ch <- sr.RemoteServiceState
|
|
||||||
|
|
||||||
case "started":
|
case "started":
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
v.client.logger.Debug("Subaru API reports remote service request (started) is in progress", "id", sr.ServiceRequestID)
|
v.client.logger.Debug("Subaru API reports remote service request (started) is in progress", "id", sr.ServiceRequestID)
|
||||||
v.executeServiceRequest(map[string]string{"serviceRequestId": sr.ServiceRequestID}, reqUrl, pollingUrl, ch, attempt+1)
|
v.executeServiceRequest(map[string]string{"serviceRequestId": sr.ServiceRequestID}, reqUrl, pollingUrl, ch, attempt+1)
|
||||||
ch <- sr.RemoteServiceState
|
|
||||||
|
|
||||||
case "stopping":
|
case "stopping":
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
v.client.logger.Debug("Subaru API reports remote service request (stopping) is in progress", "id", sr.ServiceRequestID)
|
v.client.logger.Debug("Subaru API reports remote service request (stopping) is in progress", "id", sr.ServiceRequestID)
|
||||||
v.executeServiceRequest(map[string]string{"serviceRequestId": sr.ServiceRequestID}, reqUrl, pollingUrl, ch, attempt+1)
|
v.executeServiceRequest(map[string]string{"serviceRequestId": sr.ServiceRequestID}, reqUrl, pollingUrl, ch, attempt+1)
|
||||||
ch <- sr.RemoteServiceState
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
v.client.logger.Debug("Subaru API reports remote service request (default)")
|
v.client.logger.Debug("Subaru API reports remote service request (default)")
|
||||||
v.executeServiceRequest(map[string]string{"serviceRequestId": sr.ServiceRequestID}, reqUrl, pollingUrl, ch, attempt+1)
|
v.executeServiceRequest(map[string]string{"serviceRequestId": sr.ServiceRequestID}, reqUrl, pollingUrl, ch, attempt+1)
|
||||||
ch <- sr.RemoteServiceState
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
v.client.logger.Error("error while parsing service request json", "request", reqUrl, "response", resp.Data)
|
||||||
|
return errors.New("error while parsing service request json")
|
||||||
}
|
}
|
||||||
return errors.New("response is not a service request")
|
return errors.New("response is not a service request")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user