forked from nidayand/node-red-contrib-norelite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnrl-rfxcom.js
55 lines (45 loc) · 1.37 KB
/
nrl-rfxcom.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
52
53
54
55
/*jslint node: true */
module.exports = function (RED) {
"use strict";
var common = require('../lib/common');
var Message = require("../lib/msg");
/*
Defines the output node for a rule. Copied to a large extent from 66-mongodb.js
*/
function NoreliteRfxcomOutNode(config) {
RED.nodes.createNode(this, config);
var self = this;
self.code = config.code;
self.dimmable = config.dimmable;
common.setStatus(self);
/* When a message is received */
self.on("input", function (msg) {
var omsg = new Message(self, msg);
var nmsg = {};
nmsg.topic = self.code;
var val;
if (self.dimmable) {
if (omsg.is_enabled() && omsg.getDim() > 0) {
val = "level " + (omsg.getDim() / 100);
common.setStatus(self, 1, "Dim " + omsg.getDim() + "%");
} else {
val = "Off";
common.setStatus(self, -1, "Off");
}
} else {
if (omsg.is_enabled() && omsg.getDim() > 0) {
val = "On";
common.setStatus(self, 1, "On");
} else {
val = "Off";
common.setStatus(self, -1, "Off");
}
}
nmsg.payload = val;
//Also passing the original instruction if
nmsg.instruction = omsg.toMessageObject();
self.send(nmsg);
});
}
RED.nodes.registerType("nrl-rfxcom-out", NoreliteRfxcomOutNode);
};