This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhomematic.js
96 lines (83 loc) · 2.36 KB
/
homematic.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
module.exports = function(RED) {
"use strict";
function CCUConfigNode(n) {
RED.nodes.createNode(this, n);
this.host = n.host;
this.interfaceName = n.interfaceName;
}
RED.nodes.registerType("ccu-address", CCUConfigNode);
function DeviceConfigNode(n) {
RED.nodes.createNode(this, n);
this.channel = n.channel;
}
RED.nodes.registerType("homematic-device", DeviceConfigNode);
function HomematicCommands(n) {
RED.nodes.createNode(this, n);
const node = this;
this.ccu = n.ccu;
this.device = n.device;
this.config = RED.nodes.getNode(this.ccu);
this.device = RED.nodes.getNode(this.device);
this.function = n.function;
this.attribute = n.attribute;
this.value = n.value || "";
this.nodeName = n.nodeName;
this.prepareValue = function(value, msg) {
let returnValue = value;
// make sure that only this object is possible!
if (value === "{{msg.payload}}") {
returnValue = msg.payload;
}
return returnValue;
};
this.setValue = function(interfaceName, channel, attribute, value) {
return (
'var d = dom.GetObject("' +
interfaceName +
channel +
"." +
attribute +
'");if (d){d.State("' +
value +
'");}'
);
};
this.getValue = function(interfaceName, channel, attribute) {
return (
'var d = dom.GetObject("' +
interfaceName +
channel +
"." +
attribute +
'");if (d){Write(d.State());}'
);
};
this.on("input", msg => {
let script = "";
if (this.function == "setValue") {
script = this.setValue(
this.config.interfaceName,
this.device.channel,
this.attribute,
this.prepareValue(this.value, msg)
);
}
if (this.function == "getValue") {
script = this.getValue(
this.config.interfaceName,
this.device.channel,
this.attribute
);
}
let headers = {};
headers["Content-Length"] = script.length;
headers["Content-Type"] = "application/x-www-form-urlencoded";
msg.headers = headers;
msg.method = "POST";
msg.url = "http://" + this.config.host + "/tclrega.exe";
msg.payload = script;
this.send(msg);
});
}
RED.nodes.registerType("homematic", HomematicCommands);
};