From 1d8d175be08e14c2e78cbe429e9271d32a5799d2 Mon Sep 17 00:00:00 2001 From: Alex Savin Date: Sun, 6 Jul 2025 17:33:34 -0400 Subject: [PATCH] Refactor vehicle command functions to improve readability and maintainability --- vehicle.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vehicle.go b/vehicle.go index 991da5d..0bbd169 100644 --- a/vehicle.go +++ b/vehicle.go @@ -226,6 +226,7 @@ func (v *Vehicle) Lock() (chan string, error) { "forceKeyInCar": "false"} reqUrl := MOBILE_API_VERSION + urlToGen(apiURLs["API_LOCK"], v.getAPIGen()) pollingUrl := MOBILE_API_VERSION + apiURLs["API_REMOTE_SVC_STATUS"] + ch := make(chan string) go func() { defer close(ch) @@ -250,6 +251,7 @@ func (v *Vehicle) Unlock() (chan string, error) { "unlockDoorType": "ALL_DOORS_CMD"} // FRONT_LEFT_DOOR_CMD | ALL_DOORS_CMD reqUrl := MOBILE_API_VERSION + urlToGen(apiURLs["API_UNLOCK"], v.getAPIGen()) pollingUrl := MOBILE_API_VERSION + apiURLs["API_REMOTE_SVC_STATUS"] + ch := make(chan string) go func() { defer close(ch) @@ -287,6 +289,7 @@ func (v *Vehicle) EngineStart() (chan string, error) { } reqUrl := MOBILE_API_VERSION + apiURLs["API_G2_REMOTE_ENGINE_START"] pollingUrl := MOBILE_API_VERSION + apiURLs["API_REMOTE_SVC_STATUS"] + ch := make(chan string) go func() { defer close(ch) @@ -337,11 +340,13 @@ func (v *Vehicle) LightsStart() (chan string, error) { if v.getAPIGen() == FEATURE_G1_TELEMATICS { pollingUrl = MOBILE_API_VERSION + apiURLs["API_G1_HORN_LIGHTS_STATUS"] } + ch := make(chan string) go func() { defer close(ch) v.executeServiceRequest(params, reqUrl, pollingUrl, ch, 1) }() + return ch, nil } @@ -362,6 +367,7 @@ func (v *Vehicle) LightsStop() (chan string, error) { if v.getAPIGen() == FEATURE_G1_TELEMATICS { pollingUrl = MOBILE_API_VERSION + apiURLs["API_G1_HORN_LIGHTS_STATUS"] } + ch := make(chan string) go func() { defer close(ch) @@ -388,6 +394,7 @@ func (v *Vehicle) HornStart() (chan string, error) { if v.getAPIGen() == FEATURE_G1_TELEMATICS { pollingUrl = MOBILE_API_VERSION + apiURLs["API_G1_HORN_LIGHTS_STATUS"] } + ch := make(chan string) go func() { defer close(ch) @@ -414,6 +421,7 @@ func (v *Vehicle) HornStop() (chan string, error) { if v.getAPIGen() == FEATURE_G1_TELEMATICS { pollingUrl = MOBILE_API_VERSION + apiURLs["API_G1_HORN_LIGHTS_STATUS"] } + ch := make(chan string) go func() { defer close(ch) @@ -442,9 +450,8 @@ func (v *Vehicle) ChargeOn() (chan string, error) { v.executeServiceRequest(params, reqUrl, pollingUrl, ch, 1) }() return ch, nil - } else { - return nil, errors.New("not an EV car") } + return nil, errors.New("not an EV car") } // GetLocation