-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall_ewelink_api.js
47 lines (40 loc) · 1.19 KB
/
call_ewelink_api.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
const ewelink = require('ewelink-api');
function parse_args(argument_list){
if (argument_list.length != 7){
throw "Invalid arguments lenght!";
}
return {
at: argument_list[2],
apiKey: argument_list[3],
region: argument_list[4],
device: argument_list[5],
action: argument_list[6],
}
}
(async () => {
// console.debug(process.argv);
let my_args = parse_args(process.argv);
//console.debug(my_args);
const connection = new ewelink({
at: my_args['at'],
apiKey: my_args['apiKey'],
region: my_args['region']
});
/* device actions */
switch(my_args['action']){
case 'on':
const status_on = await connection.setDevicePowerState(my_args['device'], 'on');
console.log(my_args['device'], JSON.stringify(status_on));
break;
case 'off':
const status_off = await connection.setDevicePowerState(my_args['device'], 'off');
console.log(my_args['device'], JSON.stringify(status_off));
break;
case 'status':
const status_status = await connection.getDevicePowerState(my_args['device']);
console.log(my_args['device'], JSON.stringify(status_status));
break;
default:
console.error('Operation: ', my_args['action'], ' not supported!');
}
})();