-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxiaomi-home.js
More file actions
80 lines (70 loc) · 1.57 KB
/
xiaomi-home.js
File metadata and controls
80 lines (70 loc) · 1.57 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
module.exports = function(RED) {
// use strict;
var Hub = require("node-xiaomi-smart-home").Hub;
let hub = new Hub();
hub.listen();
function xiaomiListener(config) {
RED.nodes.createNode(this,config);
var node = this;
//Clean up procedure before re-deploy
node.on('close', function(removed, doneFunction) {
hub.stop();
hub = null;
if (typeof doneFunction === 'function')
doneFunction();
RED.log.info("node-red-contrib-xiaomi-home closing done...");
});
hub.on('data.th', function (sid, temperature, humidity) {
var msg = {};
msg.title = 'th';
msg.payload = {
"event": "th",
"sid": sid,
"temperature": temperature,
"humidity": humidity
};
node.send(msg);
});
hub.on('data.button', function (sid, type) {
var msg = {};
msg.title = 'button';
msg.payload = {
"event": "button",
"sid": sid,
"type": type
};
node.send(msg);
});
hub.on('data.motion', function (sid, motion) {
var msg = {};
msg.title = 'motion';
msg.payload = {
"event": "motion",
"sid": sid,
"type": motion
};
node.send(msg);
});
hub.on('data.magnet', function (sid, closed) {
var msg = {};
msg.title = 'magnet';
msg.payload = {
"event": "magnet",
"sid": sid,
"closed": closed
};
node.send(msg);
});
hub.on('data.plug', function (sid, on) {
var msg = {};
msg.title = 'plug';
msg.payload = {
"event": "plug",
"sid": sid,
"on": on
};
node.send(msg);
});
}
RED.nodes.registerType("xiaomi-home",xiaomiListener);
}