-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebug.ts
More file actions
110 lines (102 loc) · 2.62 KB
/
debug.ts
File metadata and controls
110 lines (102 loc) · 2.62 KB
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
import config from './config.json';
import DroneMobile from './src';
import inquirer from 'inquirer';
let client: DroneMobile;
let vehicleId;
const apiCalls = {
exit: { run: () => true },
status: {
run: async () => {
const status = await client.status(vehicleId);
console.log('status', JSON.stringify(status, null, 2));
},
},
start: {
run: async () => {
const start = await client.start(vehicleId);
console.log('start', JSON.stringify(start, null, 2));
},
},
stop: {
run: async () => {
const stop = await client.stop(vehicleId);
console.log('stop', JSON.stringify(stop, null, 2));
},
},
lock: {
run: async () => {
const lock = await client.lock(vehicleId);
console.log('lock', JSON.stringify(lock, null, 2));
},
},
unlock: {
run: async () => {
const unlock = await client.unlock(vehicleId);
console.log('unlock', JSON.stringify(unlock, null, 2));
},
},
trunk: {
run: async () => {
const trunk = await client.trunk(vehicleId);
console.log('trunk', JSON.stringify(trunk, null, 2));
},
},
aux1: {
run: async () => {
const aux1 = await client.aux1(vehicleId);
console.log('aux1', JSON.stringify(aux1, null, 2));
},
},
aux2: {
run: async () => {
const aux2 = await client.aux2(vehicleId);
console.log('aux2', JSON.stringify(aux2, null, 2));
},
},
location: {
run: async () => {
const location = await client.location(vehicleId);
console.log('location:', JSON.stringify(location, null, 2));
},
},
failLogin: {
run: async () => {
createInstance({
username: 'bad@fail.now',
password: "I 'm a disappointment",
});
},
},
};
const onReadyHandler = async () => {
// get a list of vehicles on the account
const vehicleList = await client.vehicles();
vehicleId = vehicleList[0]?.device_key;
askForCommandInput();
};
const createInstance = config => {
client = new DroneMobile(config);
client.on('ready', onReadyHandler);
client.on('error', err => {
console.error(err?.message ?? err);
});
};
function askForCommandInput() {
console.log('');
inquirer
.prompt([
{
type: 'list',
name: 'command',
message: 'What you wanna do?',
choices: Object.entries(apiCalls).map(([k, v]) => k),
},
])
.then(answers => {
if (answers.command === 'exit') {
return;
}
apiCalls[answers.command].run();
});
}
createInstance(config);