-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
51 lines (41 loc) · 1.3 KB
/
test.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
const TelnetTTP = require('./dist')
const Assert = require('assert').strict
let client = new TelnetTTP();
client
.connect({
host: "192.168.10.110"
})
.catch(console.error);
client.on("data", (data) => {
console.log('data: ' + data.toString());
});
const subscriptionHandlers = {}
subscriptionHandlers["stateSubscription"] = msg => {
console.log(`logicmeter 1 is now ${JSON.stringify(msg.value)}`);
}
client.on("subscription", msg => {
let handler = subscriptionHandlers[msg.publishToken]
if (typeof handler === "function") {
handler(msg)
}
})
client.on("ready", () => {
console.log("ready");
client
.send("LogicState toggle state 1")
.then(msg => { Assert.equal(msg.message, "+OK") })
.catch(msg => Assert.fail("command 'LogicState toggle state 1' failed:" + msg));
client
.send("LogicStdate toggle state 1")
.then(msg => Assert.fail("command 'LogicStdate toggle state 1' failed:" + msg))
.catch(msg => Assert.equal(msg.message, '-ERR address not found: {"deviceId":0 "classCode":0 "instanceNum":0}'))
client.send("LogicMeter1 subscribe states stateSubscription 100")
client.send("Volume subscribe level 1 vol1 100")
client.send("DEVICE get activeFaultList").then(msg => {
console.log(msg)
}
)
});
// setTimeout(() => {
// process.exit()
// }, 5000);