diff --git a/client_test.go b/client_test.go index d90d09b..c05927b 100644 --- a/client_test.go +++ b/client_test.go @@ -194,6 +194,37 @@ func TestNew_Success(t *testing.T) { } } +func TestNew_MultiCarSuccess(t *testing.T) { + handler := func(w http.ResponseWriter, r *http.Request) { + // Handle API_LOGIN endpoint + if r.URL.Path == MOBILE_API_VERSION+apiURLs["API_LOGIN"] && r.Method == http.MethodPost { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + fmt.Fprint(w, `{"success":true,"errorCode":null,"dataName":"sessionData","data":{"sessionChanged":false,"vehicleInactivated":false,"account":{"createdDate":1612345678000,"marketId":1,"firstName":"Joe","lastName":"User","zipCode":"54321","accountKey":1234567,"lastLoginDate":1612345678000,"zipCode5":"54321"},"resetPassword":false,"deviceId":"1612345678","sessionId":"0123456789ABCDEF01234567890ABCDE","deviceRegistered":true,"passwordToken":null,"vehicles":[{"customer":{"sessionCustomer":null,"email":null,"firstName":null,"lastName":null,"zip":null,"oemCustId":null,"phone":null},"vehicleName":"TEST_SUBARU_1","stolenVehicle":false,"features":null,"vin":"JF2ABCDE6L0000001","modelYear":null,"modelCode":null,"engineSize":null,"nickname":"TEST_SUBARU_1","vehicleKey":1000001,"active":true,"licensePlate":"","licensePlateState":"","email":null,"firstName":null,"lastName":null,"subscriptionFeatures":null,"accessLevel":1,"zip":null,"oemCustId":"1-TESTOEM_1","vehicleMileage":null,"phone":null,"userOemCustId":"1-TESTOEM_1","subscriptionStatus":null,"authorizedVehicle":true,"preferredDealer":null,"cachedStateCode":"TX","subscriptionPlans":[],"crmRightToRepair":false,"needMileagePrompt":false,"phev":null,"sunsetUpgraded":true,"extDescrip":null,"intDescrip":null,"modelName":null,"transCode":null,"provisioned":true,"remoteServicePinExist":true,"needEmergencyContactPrompt":false,"vehicleGeoPosition":null,"show3gSunsetBanner":false,"timeZone":null},{"customer":{"sessionCustomer":null,"email":null,"firstName":null,"lastName":null,"zip":null,"oemCustId":null,"phone":null},"vehicleName":"TEST_SUBARU_2","stolenVehicle":false,"features":null,"vin":"JF2ABCDE6L0000002","modelYear":null,"modelCode":null,"engineSize":null,"nickname":"TEST_SUBARU_2","vehicleKey":1000002,"active":true,"licensePlate":"","licensePlateState":"","email":null,"firstName":null,"lastName":null,"subscriptionFeatures":null,"accessLevel":1,"zip":null,"oemCustId":"1-TESTOEM_2","vehicleMileage":null,"phone":null,"userOemCustId":"1-TESTOEM_2","subscriptionStatus":null,"authorizedVehicle":true,"preferredDealer":null,"cachedStateCode":"TX","subscriptionPlans":[],"crmRightToRepair":false,"needMileagePrompt":false,"phev":null,"sunsetUpgraded":true,"extDescrip":null,"intDescrip":null,"modelName":null,"transCode":null,"provisioned":true,"remoteServicePinExist":true,"needEmergencyContactPrompt":false,"vehicleGeoPosition":null,"show3gSunsetBanner":false,"timeZone":null},{"customer":{"sessionCustomer":null,"email":null,"firstName":null,"lastName":null,"zip":null,"oemCustId":null,"phone":null},"vehicleName":"TEST_SUBARU_3","stolenVehicle":false,"features":null,"vin":"JF2ABCDE6L0000003","modelYear":null,"modelCode":null,"engineSize":null,"nickname":"TEST_SUBARU_3","vehicleKey":1000003,"active":true,"licensePlate":"","licensePlateState":"","email":null,"firstName":null,"lastName":null,"subscriptionFeatures":null,"accessLevel":1,"zip":null,"oemCustId":"1-TESTOEM_3","vehicleMileage":null,"phone":null,"userOemCustId":"1-TESTOEM_3","subscriptionStatus":null,"authorizedVehicle":true,"preferredDealer":null,"cachedStateCode":"TX","subscriptionPlans":[],"crmRightToRepair":false,"needMileagePrompt":false,"phev":null,"sunsetUpgraded":true,"extDescrip":null,"intDescrip":null,"modelName":null,"transCode":null,"provisioned":true,"remoteServicePinExist":true,"needEmergencyContactPrompt":false,"vehicleGeoPosition":null,"show3gSunsetBanner":false,"timeZone":null},{"customer":{"sessionCustomer":null,"email":null,"firstName":null,"lastName":null,"zip":null,"oemCustId":null,"phone":null},"vehicleName":"TEST_SUBARU_4","stolenVehicle":false,"features":null,"vin":"JF2ABCDE6L0000004","modelYear":null,"modelCode":null,"engineSize":null,"nickname":"TEST_SUBARU_4","vehicleKey":1000004,"active":true,"licensePlate":"","licensePlateState":"","email":null,"firstName":null,"lastName":null,"subscriptionFeatures":null,"accessLevel":1,"zip":null,"oemCustId":"1-TESTOEM_4","vehicleMileage":null,"phone":null,"userOemCustId":"1-TESTOEM_4","subscriptionStatus":null,"authorizedVehicle":true,"preferredDealer":null,"cachedStateCode":"TX","subscriptionPlans":[],"crmRightToRepair":false,"needMileagePrompt":false,"phev":null,"sunsetUpgraded":true,"extDescrip":null,"intDescrip":null,"modelName":null,"transCode":null,"provisioned":true,"remoteServicePinExist":true,"needEmergencyContactPrompt":false,"vehicleGeoPosition":null,"show3gSunsetBanner":false,"timeZone":null},{"customer":{"sessionCustomer":null,"email":null,"firstName":null,"lastName":null,"zip":null,"oemCustId":null,"phone":null},"vehicleName":"TEST_SUBARU_5","stolenVehicle":false,"features":null,"vin":"JF2ABCDE6L0000005","modelYear":null,"modelCode":null,"engineSize":null,"nickname":"TEST_SUBARU_5","vehicleKey":1000005,"active":true,"licensePlate":"","licensePlateState":"","email":null,"firstName":null,"lastName":null,"subscriptionFeatures":null,"accessLevel":1,"zip":null,"oemCustId":"1-TESTOEM_5","vehicleMileage":null,"phone":null,"userOemCustId":"1-TESTOEM_5","subscriptionStatus":null,"authorizedVehicle":true,"preferredDealer":null,"cachedStateCode":"TX","subscriptionPlans":[],"crmRightToRepair":false,"needMileagePrompt":false,"phev":null,"sunsetUpgraded":true,"extDescrip":null,"intDescrip":null,"modelName":null,"transCode":null,"provisioned":true,"remoteServicePinExist":true,"needEmergencyContactPrompt":false,"vehicleGeoPosition":null,"show3gSunsetBanner":false,"timeZone":null}],"rightToRepairEnabled":true,"rightToRepairStartYear":2022,"rightToRepairStates":"MA","enableXtime":true,"termsAndConditionsAccepted":true,"digitalGlobeConnectId":"00000000-0000-0000-0000-000000000000","digitalGlobeImageTileService":"https://earthwatch.digitalglobe.com/earthservice/tmsaccess/tms/1.0.0/DigitalGlobe:ImageryTileService@EPSG:3857@png/{z}/{x}/{y}.png?connectId=00000000-0000-0000-0000-000000000000","digitalGlobeTransparentTileService":"https://earthwatch.digitalglobe.com/earthservice/tmsaccess/tms/1.0.0/Digitalglobe:OSMTransparentTMSTileService@EPSG:3857@png/{z}/{x}/{-y}.png/?connectId=00000000-0000-0000-0000-000000000000","tomtomKey":"0123456789ABCDEF01234567890ABCDE","currentVehicleIndex":0,"handoffToken":"test","satelliteViewEnabled":true,"registeredDevicePermanent":true}}`) + } + } + + ts := mockMySubaruApi(t, handler) + ts.Start() + defer ts.Close() + + cfg := mockConfig(t) + + msc, err := New(cfg) + if err != nil { + t.Fatalf("expected no error, got %v", err) + } + if msc == nil { + t.Fatalf("expected MySubaru API client, got nil") + } + if !msc.isAuthenticated || !msc.isRegistered { + t.Errorf("expected authenticated and registered true, got %v %v", msc.isAuthenticated, msc.isRegistered) + } + if msc.currentVin != "JF2ABCDE6L0000001" { + t.Errorf("expected currentVin JF2ABCDE6L0000001, got %v", msc.currentVin) + } +} + // func TestNew_Failure(t *testing.T) { // ts := mockMySubaruApi(t) // ts.Start() diff --git a/consts.go b/consts.go index ebb0ff3..79b4691 100644 --- a/consts.go +++ b/consts.go @@ -150,7 +150,7 @@ var features = map[string]string{ "PANPM-TUIRWAOC": "Power Moonroof", "PANPM-DG2G": "Panoramic Moonroof", "PHEV": "Electric Vehicle", - "RES": "Remote Start", + "RES": "Remote Engine Start", "REARBRK": "Reverse Auto Braking", "TIF_35": "Tire Pressure Front 35", "TIR_33": "Tire Pressure Rear 35", @@ -167,6 +167,7 @@ var features = map[string]string{ "RVFS": "Remote Vehicle Find System", "TLD": "Tire Pressure Low Detection", "DOOR_LU_STAT": "Door Lock/Unlock Status", + "RPOI": "Remote Geo Point of Interest", } var troubles = map[string]string{ diff --git a/mysubaru.go b/mysubaru.go index ee60541..485e389 100644 --- a/mysubaru.go +++ b/mysubaru.go @@ -355,7 +355,7 @@ type ClimateProfile struct { VehicleType string `json:"vehicleType,omitempty"` // vehicleType [ gas | phev ] PresetType string `json:"presetType"` // presetType [ subaruPreset | userPreset ] StartConfiguration string `json:"startConfiguration"` // startConfiguration [ START_ENGINE_ALLOW_KEY_IN_IGNITION (gas) | START_CLIMATE_CONTROL_ONLY_ALLOW_KEY_IN_IGNITION (phev) ] - RunTimeMinutes int `json:"runTimeMinutes,string"` // runTimeMinutes [ 5 | 10 ] + RunTimeMinutes int `json:"runTimeMinutes,string"` // runTimeMinutes [ 0 | 1 | 5 | 10 ] HeatedRearWindowActive string `json:"heatedRearWindowActive"` // heatedRearWindowActive: [ false | true ] HeatedSeatFrontRight string `json:"heatedSeatFrontRight"` // heatedSeatFrontRight: [ OFF | LOW_HEAT | MEDIUM_HEAT | HIGH_HEAT ] HeatedSeatFrontLeft string `json:"heatedSeatFrontLeft"` // heatedSeatFrontLeft: [ OFF | LOW_HEAT | MEDIUM_HEAT | HIGH_HEAT ] @@ -368,6 +368,8 @@ type ClimateProfile struct { Disabled string `json:"disabled"` // disabled [ false | true ] } +type ClimateProfiles map[string]ClimateProfile + // GeoLocation represents the geographical location of a Subaru vehicle. type GeoLocation struct { Latitude float64 `json:"latitude"` // 40.700184 diff --git a/vehicle.go b/vehicle.go index ca83ec5..5d6d1cb 100644 --- a/vehicle.go +++ b/vehicle.go @@ -643,6 +643,10 @@ func (v *Vehicle) UpdateClimateUserPresets() error { return nil } +func (v *Vehicle) DeleteClimateUserPresets() error { + return nil +} + // GetVehicleStatus . func (v *Vehicle) GetVehicleStatus() error { if !v.getRemoteOptionsStatus() {