This repository was archived by the owner on Jul 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (64 loc) · 1.95 KB
/
Copy pathindex.js
File metadata and controls
68 lines (64 loc) · 1.95 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
/**
* Includes
*/
const commandLineArgs = require('command-line-args');
const SmartCielo = require('./SmartCielo.js');
/**
* Constants
*/
const OPTION_DEFINITIONS = [
{ name: 'username', alias: 'u', type: String },
{ name: 'password', alias: 'p', type: String },
{ name: 'ip', alias: 'i', type: String },
{ name: 'verbose', alias: 'v', type: Boolean }
];
const OPTIONS = commandLineArgs(OPTION_DEFINITIONS);
/**
* Debug Proxy Settings
*/
const HttpsProxyAgent = require('https-proxy-agent');
const url = require('url');
const PROXY = 'http://127.0.0.1:8888';
const agentOptions = url.parse(PROXY);
const agent = OPTIONS.verbose ? new HttpsProxyAgent(agentOptions) : undefined;
if (agent) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
}
/**
* Example Usage.
*/
const hvac = new SmartCielo(OPTIONS.username, OPTIONS.password, OPTIONS.ip,
commandedState => {
console.log('Commanded State Change:', JSON.stringify(commandedState));
},
roomTemperature => {
console.log('Updated Room Temperature:', roomTemperature);
},
err => {
console.error('Communication Error:', err);
}, agent);
console.log('Connecting...');
hvac.waitForConnection.then(_ => {
console.log('Connected.');
console.log('Current State:', JSON.stringify(hvac.getState()));
hvac.sendPowerOn(_ => {
console.log('Sent Power On.');
setTimeout(() => {
console.log('Current State:', JSON.stringify(hvac.getState()));
hvac.sendPowerOff(_ => {
console.log('Sent Power Off.');
setTimeout(() => {
console.log('Current State:', JSON.stringify(hvac.getState()));
console.log('Exiting...');
process.exit();
}, 1000);
}, err => {
console.error(err);
});
}, 10000);
}, err => {
console.error(err);
});
}, err => {
console.error(err);
});