Skip to content

Commit 1f51c0c

Browse files
authored
Merge pull request #59 from Hacksore/develop
Fix #54 and issue with parsed status property tirePressureWarningLampAll
2 parents 2c97e73 + cef5763 commit 1f51c0c

12 files changed

Lines changed: 79 additions & 69 deletions

__tests__/controller.spec.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,21 @@ const getController = region => {
2929
};
3030

3131
describe('AmericanController', () => {
32-
it('call getVehicles and check length', async () => {
33-
const controller = getController('US');
32+
const controller = getController('US');
3433

34+
it('call login and get valid response', async () => {
35+
(got as any).mockReturnValueOnce({
36+
body: {
37+
access_token: 'jest',
38+
refresh_token: 'test',
39+
},
40+
statusCode: 200,
41+
});
42+
43+
expect(await controller.login()).toEqual('login good');
44+
});
45+
46+
it('call getVehicles and check length', async () => {
3547
(got as any).mockReturnValueOnce({
3648
body: JSON.stringify({
3749
enrolledVehicleDetails: [
@@ -58,7 +70,6 @@ describe('AmericanController', () => {
5870
});
5971

6072
describe('EuropeanController', () => {
61-
6273
it('call getVehicles and check length', async () => {
6374
const controller = getController('EU');
6475
controller.session.accessToken = 'MockToken';
@@ -75,25 +86,25 @@ describe('EuropeanController', () => {
7586
regId: '123123',
7687
gen: '2',
7788
name: 'Car',
78-
id: '12345',
89+
id: '12345',
7990
},
8091
],
8192
},
8293
},
8394
statusCode: 200,
8495
});
85-
96+
8697
(got as any).mockReturnValueOnce({
8798
body: {
8899
resMsg: {
89100
vinInfo: [
90-
{
101+
{
91102
basic: {
92103
modelYear: '2019',
93104
vin: '5555',
94-
id: '123456'
95-
}
96-
}
105+
id: '123456',
106+
},
107+
},
97108
],
98109
},
99110
},
@@ -106,8 +117,7 @@ describe('EuropeanController', () => {
106117
});
107118

108119
describe('CanadianController', () => {
109-
110-
it('call getVehicles and check length', async () => {
120+
it('call getVehicles and check length', async () => {
111121
const controller = getController('CA');
112122

113123
(got as any).mockReturnValueOnce({

lib/constants/america.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
//TODO: Someone needs to figure out the Kia endpoints
2+
// we can then make a fork easier to maintain
3+
14
export const API_HOST = 'api.telematics.hyundaiusa.com';
25

3-
export const BASE_URL = 'https://api.telematics.hyundaiusa.com';
6+
export const BASE_URL = `https://${API_HOST}`;
47
export const CLIENT_ID = '815c046afaa4471aa578827ad546cc76';
58
export const CLIENT_SECRET = 'GXZveJJAVTehh/OtakM3EQ==';

lib/constants/canada.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1+
// Kia seems to use myuvo.ca as mentioned by @wcomartin
2+
// forks can modify some things to make this work
3+
export const CA_API_HOST = 'mybluelink.ca';
4+
export const CA_BASE_URL = `https://${CA_API_HOST}`;
15
export const CLIENT_ORIGIN = 'SPA';
2-
export const CA_BASE_URL = 'https://mybluelink.ca';
36

47
export const CA_ENDPOINTS = {
5-
login: `${CA_BASE_URL}/tods/api/lgn`,
6-
logout: `${CA_BASE_URL}/tods/api/lgout`,
7-
// Account
8-
myAccount: `${CA_BASE_URL}/tods/api/acctinfo`,
9-
nextService: `${CA_BASE_URL}/tods/api/nxtsvc`,
10-
preferedDealer: `${CA_BASE_URL}/tods/api/gtprfrdlr`,
11-
// Vehicle
12-
vehicleList: `${CA_BASE_URL}/tods/api/vhcllst`,
13-
vehicleInfo: `${CA_BASE_URL}/tods/api/sltvhcl`,
14-
status: `${CA_BASE_URL}/tods/api/lstvhclsts`,
15-
remoteStatus: `${CA_BASE_URL}/tods/api/rltmvhclsts`,
16-
// Car commands with preauth (PIN)
17-
lock: `${CA_BASE_URL}/tods/api/drlck`,
18-
unlock: `${CA_BASE_URL}/tods/api/drulck`,
19-
start: `${CA_BASE_URL}/tods/api/evc/rfon`,
20-
stop: `${CA_BASE_URL}/tods/api/evc/rfoff`,
21-
locate: `${CA_BASE_URL}/tods/api/fndmcr`,
22-
hornlight: `${CA_BASE_URL}/tods/api/hornlight`,
23-
// System
24-
verifyAccountToken: `${CA_BASE_URL}/tods/api/vrfyacctkn`,
25-
verifyPin: `${CA_BASE_URL}/tods/api/vrfypin`,
26-
verifyToken: `${CA_BASE_URL}/tods/api/vrfytnc`,
27-
};
8+
login: `${CA_BASE_URL}/tods/api/lgn`,
9+
logout: `${CA_BASE_URL}/tods/api/lgout`,
10+
// Account
11+
myAccount: `${CA_BASE_URL}/tods/api/acctinfo`,
12+
nextService: `${CA_BASE_URL}/tods/api/nxtsvc`,
13+
preferedDealer: `${CA_BASE_URL}/tods/api/gtprfrdlr`,
14+
// Vehicle
15+
vehicleList: `${CA_BASE_URL}/tods/api/vhcllst`,
16+
vehicleInfo: `${CA_BASE_URL}/tods/api/sltvhcl`,
17+
status: `${CA_BASE_URL}/tods/api/lstvhclsts`,
18+
remoteStatus: `${CA_BASE_URL}/tods/api/rltmvhclsts`,
19+
// Car commands with preauth (PIN)
20+
lock: `${CA_BASE_URL}/tods/api/drlck`,
21+
unlock: `${CA_BASE_URL}/tods/api/drulck`,
22+
start: `${CA_BASE_URL}/tods/api/evc/rfon`,
23+
stop: `${CA_BASE_URL}/tods/api/evc/rfoff`,
24+
locate: `${CA_BASE_URL}/tods/api/fndmcr`,
25+
hornlight: `${CA_BASE_URL}/tods/api/hornlight`,
26+
// System
27+
verifyAccountToken: `${CA_BASE_URL}/tods/api/vrfyacctkn`,
28+
verifyPin: `${CA_BASE_URL}/tods/api/vrfypin`,
29+
verifyToken: `${CA_BASE_URL}/tods/api/vrfytnc`,
30+
};

lib/constants/europe.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export const EU_BASE_URL = 'https://prd.eu-ccapi.hyundai.com:8080';
1+
export const EU_API_HOST = 'prd.eu-ccapi.hyundai.com:8080';
2+
export const EU_BASE_URL = `https://${EU_API_HOST}`;
23

34
export const EU_ENDPOINTS = {
45
session: `${EU_BASE_URL}/api/v1/user/oauth2/authorize?response_type=code&state=test&client_id=6d477c38-3ca4-4cf3-9557-2a1929a94654&redirect_uri=${EU_BASE_URL}/api/v1/user/oauth2/redirect`,
@@ -13,3 +14,5 @@ export const EU_CONSTANTS = {
1314
'Basic NmQ0NzdjMzgtM2NhNC00Y2YzLTk1NTctMmExOTI5YTk0NjU0OktVeTQ5WHhQekxwTHVvSzB4aEJDNzdXNlZYaG10UVI5aVFobUlGampvWTRJcHhzVg==',
1415
GCMSenderID: '199360397125',
1516
};
17+
18+
export const EU_CLIENT_ID = '6d477c38-3ca4-4cf3-9557-2a1929a94654';

lib/controllers/american.controller.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class AmericanController extends SessionController {
4646
return Promise.resolve('Token not expired, no need to refresh');
4747
}
4848

49+
// TODO: come up with a better return value?
4950
public async login(): Promise<string> {
5051
try {
5152
logger.debug('Logging in to API');
@@ -63,6 +64,10 @@ export class AmericanController extends SessionController {
6364
json: true,
6465
});
6566

67+
if (response.statusCode !== 200) {
68+
return Promise.resolve('login bad');
69+
}
70+
6671
this.session.accessToken = response.body.access_token;
6772
this.session.refreshToken = response.body.refresh_token;
6873
this.session.tokenExpiresAt = Math.floor(

lib/controllers/canadian.controller.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,6 @@ export class CanadianController extends SessionController {
7979
brandIndicator: vehicle.brandIndicator,
8080
regId: vehicle.regid,
8181
generation: vehicle.genType,
82-
// pin: this.config.pin,
83-
// vehicleId: vehicle.vehicleId,
84-
// vin: vehicle.vin,
85-
// nickname: vehicle.nickName,
86-
// defaultVehicle: vehicle.defaultVehicle,
87-
// modelName: vehicle.modelName,
88-
// modelYear: vehicle.modelYear,
89-
// fuelKindCode: vehicle.fuelKindCode,
90-
// genType: vehicle.genType,
91-
// subscriptionEndDate: vehicle.subscriptionEndDate,
92-
// mileageForNextService: vehicle.mileageForNextService,
93-
// daysForNextService: vehicle.daysForNextService,
9482
} as VehicleRegisterOptions;
9583

9684
this.vehicles.push(new CanadianVehicle(vehicleConfig, this));
@@ -105,7 +93,7 @@ export class CanadianController extends SessionController {
10593
//////////////////////////////////////////////////////////////////////////////
10694
// Account
10795
//////////////////////////////////////////////////////////////////////////////
108-
96+
// TODO: deprecated account specific data
10997
public async myAccount(): Promise<AccountInfo> {
11098
logger.info('Begin myAccount request');
11199
try {

lib/controllers/european.controller.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EU_CONSTANTS, EU_BASE_URL } from './../constants/europe';
1+
import { EU_CONSTANTS, EU_BASE_URL, EU_API_HOST, EU_CLIENT_ID } from './../constants/europe';
22
import { BlueLinkyConfig, Session } from './../interfaces/common.interfaces';
33
import * as pr from 'push-receiver';
44
import got from 'got';
@@ -27,7 +27,7 @@ export class EuropeanController extends SessionController {
2727
controlToken: undefined,
2828
deviceId: this.uuidv4(),
2929
tokenExpiresAt: 0,
30-
controlTokenExpiresAt: 0
30+
controlTokenExpiresAt: 0,
3131
};
3232

3333
private vehicles: Array<EuropeanVehicle> = [];
@@ -80,15 +80,15 @@ export class EuropeanController extends SessionController {
8080
method: 'POST',
8181
json: true,
8282
body: {
83-
"email": this.userConfig.username,
84-
"password": this.userConfig.password,
83+
'email': this.userConfig.username,
84+
'password': this.userConfig.password,
8585
},
8686
cookieJar,
8787
});
8888

89-
if(authCodeResponse){
89+
if (authCodeResponse) {
9090
const regexMatch = /code=([^&]*)/g.exec(authCodeResponse.body.redirectUrl);
91-
if(regexMatch !== null){
91+
if (regexMatch !== null) {
9292
this.session.refreshToken = regexMatch[1];
9393
} else {
9494
throw new Error('@EuropeControllerLogin: AuthCode was not found');
@@ -99,10 +99,9 @@ export class EuropeanController extends SessionController {
9999
const notificationReponse = await got(`${EU_BASE_URL}/api/v1/spa/notifications/register`, {
100100
method: 'POST',
101101
headers: {
102-
'ccsp-service-id': '6d477c38-3ca4-4cf3-9557-2a1929a94654',
102+
'ccsp-service-id': EU_CLIENT_ID,
103103
'Content-Type': 'application/json;charset=UTF-8',
104-
'Content-Length': '231',
105-
'Host': 'prd.eu-ccapi.hyundai.com:8080',
104+
'Host': EU_API_HOST,
106105
'Connection': 'Keep-Alive',
107106
'Accept-Encoding': 'gzip',
108107
'User-Agent': 'okhttp/3.10.0',
@@ -115,15 +114,15 @@ export class EuropeanController extends SessionController {
115114
json: true,
116115
});
117116

118-
if(notificationReponse) {
117+
if (notificationReponse) {
119118
this.session.deviceId = notificationReponse.body.resMsg.deviceId;
120119
}
121120

122121
const formData = new URLSearchParams();
123122
formData.append('grant_type', 'authorization_code');
124123
formData.append('redirect_uri', ALL_ENDPOINTS.EU.redirectUri);
125124

126-
if(this.session.refreshToken){
125+
if (this.session.refreshToken) {
127126
formData.append('code', this.session.refreshToken);
128127
}
129128

@@ -132,8 +131,7 @@ export class EuropeanController extends SessionController {
132131
headers: {
133132
'Authorization': EU_CONSTANTS.basicToken,
134133
'Content-Type': 'application/x-www-form-urlencoded',
135-
'Content-Length': '154',
136-
'Host': 'prd.eu-ccapi.hyundai.com:8080',
134+
'Host': EU_API_HOST,
137135
'Connection': 'Keep-Alive',
138136
'Accept-Encoding': 'gzip',
139137
'User-Agent': 'okhttp/3.10.0',
@@ -146,7 +144,7 @@ export class EuropeanController extends SessionController {
146144
Promise.reject(`Get token failed: ${err}`);
147145
});
148146

149-
if(response){
147+
if (response) {
150148
const responseBody = JSON.parse(response.body);
151149
this.session.accessToken = 'Bearer ' + responseBody.access_token;
152150
}

lib/vehicles/american.vehicle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export default class AmericanVehicle extends Vehicle {
189189
frontLeft: !!vehicleStatus.tirePressureLamp.tirePressureWarningLampFrontLeft,
190190
frontRight: !!vehicleStatus.tirePressureLamp.tirePressureWarningLampFrontRight,
191191
rearRight: !!vehicleStatus.tirePressureLamp.tirePressureWarningLampRearRight,
192-
all: !!vehicleStatus.tirePressureLamp.trunkOpenStatus,
192+
all: !!vehicleStatus.tirePressureLamp.tirePressureWarningLampAll,
193193
},
194194
},
195195
climate: {

lib/vehicles/canadian.vehicle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class CanadianVehicle extends Vehicle {
8686
frontLeft: !!vehicleStatus.tirePressureLamp.tirePressureWarningLampFrontLeft,
8787
frontRight: !!vehicleStatus.tirePressureLamp.tirePressureWarningLampFrontRight,
8888
rearRight: !!vehicleStatus.tirePressureLamp.tirePressureWarningLampRearRight,
89-
all: !!vehicleStatus.tirePressureLamp.trunkOpenStatus,
89+
all: !!vehicleStatus.tirePressureLamp.tirePressureWarningLampAll,
9090
},
9191
},
9292
climate: {

lib/vehicles/european.vehicle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export default class EuropeanVehicle extends Vehicle {
195195
frontLeft: !!vehicleStatus.tirePressureLamp.tirePressureLampFL,
196196
frontRight: !!vehicleStatus.tirePressureLamp.tirePressureLampFR,
197197
rearRight: !!vehicleStatus.tirePressureLamp.tirePressureLampRR,
198-
all: !!vehicleStatus.tirePressureLamp.tirePressureLampAll,
198+
all: !!vehicleStatus.tirePressureLamp.tirePressureWarningLampAll,
199199
},
200200
},
201201
climate: {

0 commit comments

Comments
 (0)