Skip to content

Commit f29c85a

Browse files
authored
feat: add australia region support (#258)
1 parent a5223a9 commit f29c85a

17 files changed

+1390
-142
lines changed

debug.ts

+39-41
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ const askForRegionInput = () => {
4545
type: 'list',
4646
name: 'region',
4747
message: 'What Region are you in?',
48-
choices: ['CN','US', 'EU', 'CA'],
48+
choices: ['CN', 'US', 'EU', 'CA', 'AU'],
4949
},
5050
{
5151
type: 'list',
5252
name: 'brand',
5353
message: 'Which brand are you using?',
5454
choices: ['hyundai', 'kia'],
55-
}
55+
},
5656
])
5757
.then(answers => {
5858
if (answers.command == 'exit') {
5959
return;
6060
} else {
61-
console.log(answers)
61+
console.log(answers);
6262
console.log('Logging in...');
6363
createInstance(answers.region, answers.brand);
6464
}
@@ -72,7 +72,7 @@ const createInstance = (region, brand) => {
7272
password,
7373
region,
7474
brand,
75-
pin
75+
pin,
7676
});
7777
client.on('ready', onReadyHandler);
7878
};
@@ -187,31 +187,30 @@ async function performCommand(command) {
187187
case 'drvInfo':
188188
const info = await vehicle.driveHistory();
189189
console.log('drvInfo : ');
190-
console.dir(info,{ depth: null });
190+
console.dir(info, { depth: null });
191191
break;
192192
case 'tripInfo':
193193
const currentYear = new Date().getFullYear();
194-
const { year, month, day } = await inquirer
195-
.prompt([
196-
{
197-
type: 'list',
198-
name: 'year',
199-
message: 'Which year?',
200-
choices: new Array(currentYear - 2015).fill(0).map((_, i) => currentYear - i),
201-
},
202-
{
203-
type: 'list',
204-
name: 'month',
205-
message: 'Which month?',
206-
choices: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
207-
},
208-
{
209-
type: 'list',
210-
name: 'day',
211-
message: 'Which day (0 to ignore the day)?',
212-
choices: new Array(32).fill(0).map((_, i) => i),
213-
}
214-
]);
194+
const { year, month, day } = await inquirer.prompt([
195+
{
196+
type: 'list',
197+
name: 'year',
198+
message: 'Which year?',
199+
choices: new Array(currentYear - 2015).fill(0).map((_, i) => currentYear - i),
200+
},
201+
{
202+
type: 'list',
203+
name: 'month',
204+
message: 'Which month?',
205+
choices: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
206+
},
207+
{
208+
type: 'list',
209+
name: 'day',
210+
message: 'Which day (0 to ignore the day)?',
211+
choices: new Array(32).fill(0).map((_, i) => i),
212+
},
213+
]);
215214
const trips = await vehicle.tripInfo({ year, month, day: day === 0 ? undefined : day });
216215
console.log('trips : ' + JSON.stringify(trips, null, 2));
217216
break;
@@ -226,21 +225,20 @@ async function performCommand(command) {
226225
await vehicle.stopCharge();
227226
break;
228227
case 'setChargeTargets':
229-
const { fast, slow } = await inquirer
230-
.prompt([
231-
{
232-
type: 'list',
233-
name: 'fast',
234-
message: 'What fast charge limit do you which to set?',
235-
choices: [50, 60, 70, 80, 90, 100],
236-
},
237-
{
238-
type: 'list',
239-
name: 'slow',
240-
message: 'What slow charge limit do you which to set?',
241-
choices: [50, 60, 70, 80, 90, 100],
242-
}
243-
]);
228+
const { fast, slow } = await inquirer.prompt([
229+
{
230+
type: 'list',
231+
name: 'fast',
232+
message: 'What fast charge limit do you which to set?',
233+
choices: [50, 60, 70, 80, 90, 100],
234+
},
235+
{
236+
type: 'list',
237+
name: 'slow',
238+
message: 'What slow charge limit do you which to set?',
239+
choices: [50, 60, 70, 80, 90, 100],
240+
},
241+
]);
244242
await vehicle.setChargeTargets({ fast, slow });
245243
console.log('targets : OK');
246244
break;

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
"format": "prettier --write './src/**/*.{js,jsx,ts,tsx}'",
1313
"prepublishOnly": "npm run build",
1414
"test": "jest --verbose",
15-
"debug": "cross-env LOG_LEVEL=debug ts-node debug.ts",
15+
"debug": "ts-node debug.ts",
1616
"eu:export:cfb": "cross-env LOG_LEVEL=debug ts-node ./scripts/export_eu_cfb.ts",
17+
"au:export:cfb": "cross-env LOG_LEVEL=debug ts-node ./scripts/export_au_cfb.ts",
1718
"test-ca": "npm run build && node test-ca.js",
1819
"watch": "tsc -w"
1920
},

scripts/export_au_cfb.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { getBrandEnvironment } from '../src/constants/australia';
2+
import { exportCfb } from './export_cfb';
3+
4+
exportCfb('hacksore/hks:native-au', 'australia.cfb.ts', getBrandEnvironment).catch(e =>
5+
console.error(e)
6+
);

scripts/export_cfb.ts

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* eslint-disable no-console */
2+
import { execSync, spawn } from 'child_process';
3+
import { writeFileSync } from 'fs';
4+
import { join } from 'path';
5+
import { AustraliaBrandEnvironment } from '../src/constants/australia';
6+
import { EuropeanBrandEnvironment } from '../src/constants/europe';
7+
import { Brand } from '../src/interfaces/common.interfaces';
8+
9+
const brands: Brand[] = ['kia', 'hyundai'];
10+
11+
export const exportCfb = async (
12+
dockerImage: string,
13+
outputFilename: string,
14+
getBrandEnvironment: (config: {
15+
brand: Brand;
16+
}) => EuropeanBrandEnvironment | AustraliaBrandEnvironment
17+
) => {
18+
console.debug(`Pulling image ${dockerImage}`);
19+
execSync(`docker pull ${dockerImage}`);
20+
const brandCFB = {
21+
kia: '',
22+
hyundai: '',
23+
};
24+
for (const brand of brands) {
25+
try {
26+
const { appId } = getBrandEnvironment({ brand });
27+
28+
const [first] = await new Promise<string[]>((resolve, reject) => {
29+
console.debug(`Starting image ${dockerImage} - ${brand}`);
30+
const process = spawn('docker', [
31+
'run',
32+
'--rm',
33+
dockerImage,
34+
brand,
35+
'dumpCFB',
36+
`${appId}:${Date.now()}`,
37+
]);
38+
const list: Array<string> = [];
39+
let errors = '';
40+
41+
process.stdout.on('data', data => {
42+
const chunk: Array<string> = data
43+
.toString()
44+
.split('\n')
45+
.map(s => s.trim())
46+
.filter(s => s != '');
47+
list.push(...chunk);
48+
});
49+
50+
process.stderr.on('data', data => {
51+
errors += data + '\n';
52+
});
53+
54+
process.on('close', code => {
55+
console.debug(`Done with ${dockerImage} - ${brand}`);
56+
if (code === 0) {
57+
return resolve(list);
58+
}
59+
reject(errors);
60+
});
61+
});
62+
brandCFB[brand] = first;
63+
} catch (e) {
64+
// Skip any unsupported brands in regions
65+
continue;
66+
}
67+
}
68+
69+
const cfbFile = `// Auto generated file on ${new Date().toISOString()}
70+
// run \`npm run eu:export:cfb\` or \`npm run au:export:cfb\` respectively to update it
71+
72+
export const kiaCFB = Buffer.from('${brandCFB.kia}', 'base64');
73+
export const hyundaiCFB = Buffer.from('${brandCFB.hyundai}', 'base64');`;
74+
75+
writeFileSync(join(__dirname, '..', 'src', 'constants', outputFilename), cfbFile);
76+
};

scripts/export_eu_cfb.ts

+2-64
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,4 @@
1-
/* eslint-disable no-console */
2-
import { execSync, spawn } from 'child_process';
3-
import { writeFileSync } from 'fs';
4-
import { join } from 'path';
51
import { getBrandEnvironment } from '../src/constants/europe';
6-
import { Brand } from '../src/interfaces/common.interfaces';
2+
import { exportCfb } from './export_cfb';
73

8-
const brands: Brand[] = ['kia', 'hyundai'];
9-
10-
const main = async () => {
11-
console.debug(`Pulling image hacksore/hks:native`);
12-
execSync('docker pull hacksore/hks:native');
13-
const brandCFB = {
14-
kia: '',
15-
hyundai: '',
16-
};
17-
for (const brand of brands) {
18-
const { appId } = getBrandEnvironment({ brand });
19-
20-
const [first] = await new Promise<string[]>((resolve, reject) => {
21-
console.debug(`Starting image hacksore/hks:native - ${brand}`);
22-
const process = spawn('docker', [
23-
'run',
24-
'--rm',
25-
'hacksore/hks:native',
26-
brand,
27-
'dumpCFB',
28-
`${appId}:${Date.now()}`,
29-
]);
30-
const list: Array<string> = [];
31-
let errors = '';
32-
33-
process.stdout.on('data', data => {
34-
const chunk: Array<string> = data
35-
.toString()
36-
.split('\n')
37-
.map(s => s.trim())
38-
.filter(s => s != '');
39-
list.push(...chunk);
40-
});
41-
42-
process.stderr.on('data', data => {
43-
errors += data + '\n';
44-
});
45-
46-
process.on('close', code => {
47-
console.debug(`Done with hacksore/hks:native - ${brand}`);
48-
if (code === 0) {
49-
return resolve(list);
50-
}
51-
reject(errors);
52-
});
53-
});
54-
brandCFB[brand] = first;
55-
}
56-
57-
const cfbFile = `// Auto generated file on ${new Date().toISOString()}
58-
// run \`npm run eu:export:cfb\` to update it
59-
60-
export const kiaCFB = Buffer.from('${brandCFB.kia}', 'base64');
61-
export const hyundaiCFB = Buffer.from('${brandCFB.hyundai}', 'base64');`;
62-
63-
writeFileSync(join(__dirname, '..', 'src', 'constants', 'europe.cfb.ts'), cfbFile);
64-
};
65-
66-
main().catch(e => console.error(e));
4+
exportCfb('hacksore/hks:native', 'europe.cfb.ts', getBrandEnvironment).catch(e => console.error(e));

src/constants.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import {
1111
getBrandEnvironment as getCNBrandEnvironment,
1212
ChineseBrandEnvironment,
1313
} from './constants/china';
14+
import {
15+
getBrandEnvironment as getAUBrandEnvironment,
16+
AustraliaBrandEnvironment,
17+
} from './constants/australia';
1418

1519
import { Brand, VehicleStatusOptions } from './interfaces/common.interfaces';
1620

@@ -21,16 +25,19 @@ export const ALL_ENDPOINTS = {
2125
getEUBrandEnvironment({ brand }).endpoints,
2226
CN: (brand: Brand): ChineseBrandEnvironment['endpoints'] =>
2327
getCNBrandEnvironment({ brand }).endpoints,
28+
AU: (brand: Brand): AustraliaBrandEnvironment['endpoints'] =>
29+
getAUBrandEnvironment({ brand }).endpoints,
2430
};
2531

2632
export const GEN2 = 2;
2733
export const GEN1 = 1;
28-
export type REGION = 'US' | 'CA' | 'EU' | 'CN';
34+
export type REGION = 'US' | 'CA' | 'EU' | 'CN' | 'AU';
2935
export enum REGIONS {
3036
US = 'US',
3137
CA = 'CA',
3238
EU = 'EU',
3339
CN = 'CN',
40+
AU = 'AU',
3441
}
3542

3643
// ev stuffz

src/constants/australia.cfb.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Auto generated file on 2024-03-20T22:41:31.183Z
2+
// run `npm run eu:export:cfb` or `npm run au:export:cfb` respectively to update it
3+
4+
export const kiaCFB = Buffer.from('IDbMgWBXgic4MAyMgf5PFFRAdGX5O3IyC3uvN3scCs0gDpTFDuyvBorlAH9JMM2/hys=', 'base64');
5+
export const hyundaiCFB = Buffer.from('V60WkEmyRQaAfrBF1623/7QL62MjLVbCHdItGzQ1g5T/hkmKmMVTaMHv4cKGzgD3kfc=', 'base64');

0 commit comments

Comments
 (0)