-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathtest-ca.js
129 lines (118 loc) · 4.25 KB
/
test-ca.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* eslint-disable */
const config = require('./config.json');
const BlueLinky = require('./dist/index');
const inquirer = require('inquirer');
const client = new BlueLinky({
region: 'CA',
...config
});
const apiCalls = [
{ name: 'exit', value: 'exit' },
{ name: 'locate', value: 'locate' },
{ name: 'status (on bluelink)', value: 'status' },
{ name: 'status refresh (fetch vehicle)', value: 'statusR' },
{ name: 'start', value: 'start' },
{ name: 'stop', value: 'stop' },
{ name: 'lock', value: 'lock' },
{ name: 'unlock', value: 'unlock' },
{ name: 'honk', value: 'honk' },
{ name: 'light', value: 'light' },
{ name: 'myAccount', value: 'myAccount' },
{ name: 'vehicleInfo', value: 'vehicleInfo' },
{ name: 'nextService', value: 'nextService' },
{ name: 'preferedDealer', value: 'preferedDealer' },
]
var vehicle
const onReadyHandler = async(vehicles) => {
vehicle = await client.getVehicle();
askForInput();
}
client.on('ready', onReadyHandler);
return
function askForInput() {
console.log("")
inquirer
.prompt([{
type: 'list',
name: 'command',
message: "What you wanna do?",
choices: apiCalls
}])
.then(answers => {
if (answers.command == 'exit') {
console.log('bye')
return
} else {
performCommand(answers.command)
}
})
}
async function performCommand(command) {
try {
switch (command) {
case 'exit':
return
case 'locate':
const locate = await vehicle.locate();
console.log('locate : ' + JSON.stringify(locate, null, 2));
break
case 'status':
const status = await vehicle.status(false);
console.log('status : ' + JSON.stringify(status, null, 2));
break
case 'statusR':
const statusR = await vehicle.status(true);
console.log('status remote : ' + JSON.stringify(statusR, null, 2));
break
case 'start':
const startRes = await vehicle.start({
airCtrl: true,
airTempvalue: 17,
defrost: true,
heating1: true
});
console.log('start : ' + JSON.stringify(startRes, null, 2));
break
case 'stop':
const stopRes = await vehicle.stop();
console.log('stop : ' + JSON.stringify(stopRes, null, 2));
break
case 'lock':
const lockRes = await vehicle.lock();
console.log('lock : ' + JSON.stringify(lockRes, null, 2));
break
case 'unlock':
const unlockRes = await vehicle.unlock();
console.log('unlock : ' + JSON.stringify(unlockRes, null, 2));
break
case 'honk':
const honkRes = await vehicle.lights(true);
console.log('honk : ' + JSON.stringify(honkRes, null, 2));
break
case 'light':
const lightRes = await vehicle.lights();
console.log('ilght : ' + JSON.stringify(lightRes, null, 2));
break
case 'vehicleInfo':
const vehicleInfo = await vehicle.vehicleInfo();
console.log('vehicleInfo : ' + JSON.stringify(vehicleInfo, null, 2));
break
case 'nextService':
const nextService = await vehicle.nextService();
console.log('nextService : ' + JSON.stringify(nextService, null, 2));
break
case 'myAccount':
const myAccount = await client.controller.myAccount();
console.log('myAccount : ' + JSON.stringify(myAccount, null, 2));
break
case 'preferedDealer':
const preferedDealer = await client.controller.preferedDealer();
console.log('preferedDealer : ' + JSON.stringify(preferedDealer, null, 2));
break
}
askForInput()
} catch (err) {
console.log(err);
}
}
askForInput();