/
myhome-eventsession.js
51 lines (46 loc) · 1.81 KB
/
myhome-eventsession.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
/*jshint esversion: 7, strict: implied, node: true */
module.exports = function (RED) {
let mhutils = require ('./myhome-utils');
function MyHomeEventSessionNode (config) {
RED.nodes.createNode (this, config);
var node = this;
let gateway = RED.nodes.getNode (config.gateway);
let runningMonitor = new mhutils.eventsMonitor (gateway);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Add all listerners on gateway based on types we have to monitor
// Define the function which is to be called on any triggered command received from the gateway
const listenerFunction = function (frame) {
node.send ({payload: frame});
};
// LIGHTS
if (config.own_lights) {
runningMonitor.addMonitoredEvent ('OWN_LIGHTS', listenerFunction);
}
// SHUTTERS
if (config.own_shutters) {
runningMonitor.addMonitoredEvent ('OWN_SHUTTERS', listenerFunction);
}
// TEMPERATURE MANAGEMENT
if (config.own_temperature) {
runningMonitor.addMonitoredEvent ('OWN_TEMPERATURE', listenerFunction);
}
// SCENARIO MANAGEMENT
if (config.own_scenario) {
runningMonitor.addMonitoredEvent ('OWN_SCENARIO', listenerFunction);
}
// ENERGY MANAGEMENT
if (config.own_energy) {
runningMonitor.addMonitoredEvent ('OWN_ENERGY', listenerFunction);
}
// OTHERS
if (config.own_others) {
runningMonitor.addMonitoredEvent ('OWN_OTHERS', listenerFunction);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
node.on ('close', function(done) {
runningMonitor.clearAllMonitoredEvents ();
done();
});
}
RED.nodes.registerType ("myhome-eventsession", MyHomeEventSessionNode);
};