smart-nodes 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/text-exec/text-exec.js +30 -23
package/package.json
CHANGED
package/text-exec/text-exec.js
CHANGED
|
@@ -10,10 +10,7 @@ module.exports = function (RED)
|
|
|
10
10
|
let log = [];
|
|
11
11
|
let rooms = [];
|
|
12
12
|
|
|
13
|
-
let lookup =
|
|
14
|
-
light: [],
|
|
15
|
-
shutter: []
|
|
16
|
-
};
|
|
13
|
+
let lookup = [];
|
|
17
14
|
|
|
18
15
|
node.on("input", function (msg)
|
|
19
16
|
{
|
|
@@ -113,6 +110,7 @@ module.exports = function (RED)
|
|
|
113
110
|
break;
|
|
114
111
|
|
|
115
112
|
case "prozent":
|
|
113
|
+
case "%":
|
|
116
114
|
case "percent":
|
|
117
115
|
case "percentage":
|
|
118
116
|
// node.log("Set action to position");
|
|
@@ -130,7 +128,7 @@ module.exports = function (RED)
|
|
|
130
128
|
|
|
131
129
|
case "und":
|
|
132
130
|
case "and":
|
|
133
|
-
if (performAction(mode, action, affectedNodes))
|
|
131
|
+
if (performAction(mode, action, number, affectedNodes))
|
|
134
132
|
{
|
|
135
133
|
action = null;
|
|
136
134
|
affectedNodes = [];
|
|
@@ -146,18 +144,26 @@ module.exports = function (RED)
|
|
|
146
144
|
let room = rooms[parseInt(word.substring(1), 10)];
|
|
147
145
|
// node.log("Found room " + room);
|
|
148
146
|
|
|
149
|
-
if (lookup[
|
|
147
|
+
if (lookup[room] && Array.isArray(lookup[room]))
|
|
150
148
|
{
|
|
151
|
-
for (const node of lookup[
|
|
149
|
+
for (const node of lookup[room])
|
|
152
150
|
{
|
|
153
151
|
if (!affectedNodes.includes(node))
|
|
154
152
|
affectedNodes.push(node);
|
|
155
153
|
}
|
|
156
154
|
}
|
|
157
155
|
}
|
|
158
|
-
else if (
|
|
156
|
+
else if (isFinite(word))
|
|
159
157
|
{
|
|
160
158
|
number = parseInt(word, 10);
|
|
159
|
+
// node.log("Found number " + number);
|
|
160
|
+
}
|
|
161
|
+
else if (word[word.length - 1] == "%" && isFinite(word.substr(0, word.length - 1)))
|
|
162
|
+
{
|
|
163
|
+
number = parseInt(word.substr(0, word.length - 1), 10);
|
|
164
|
+
mode = "shutter";
|
|
165
|
+
action = "position";
|
|
166
|
+
// node.log("Found number " + number + " with %");
|
|
161
167
|
}
|
|
162
168
|
else
|
|
163
169
|
{
|
|
@@ -167,7 +173,7 @@ module.exports = function (RED)
|
|
|
167
173
|
}
|
|
168
174
|
}
|
|
169
175
|
|
|
170
|
-
performAction(mode, action, affectedNodes);
|
|
176
|
+
performAction(mode, action, number, affectedNodes);
|
|
171
177
|
|
|
172
178
|
// node.log("Finished");
|
|
173
179
|
// node.log(log);
|
|
@@ -196,22 +202,14 @@ module.exports = function (RED)
|
|
|
196
202
|
{
|
|
197
203
|
case "smart_light-control":
|
|
198
204
|
case "smart_scene-control":
|
|
199
|
-
// node.log("Add room " + name);
|
|
200
|
-
if (!lookup.light[name])
|
|
201
|
-
lookup.light[name] = [];
|
|
202
|
-
|
|
203
|
-
if (!lookup.light[name].includes(linkedNode))
|
|
204
|
-
lookup.light[name].push(linkedNode);
|
|
205
|
-
break;
|
|
206
|
-
|
|
207
205
|
case "smart_shutter-control":
|
|
208
206
|
case "smart_shutter-complex-control":
|
|
209
207
|
// node.log("Add room " + name);
|
|
210
|
-
if (!lookup
|
|
211
|
-
lookup
|
|
208
|
+
if (!lookup[name])
|
|
209
|
+
lookup[name] = [];
|
|
212
210
|
|
|
213
|
-
if (!lookup
|
|
214
|
-
lookup
|
|
211
|
+
if (!lookup[name].includes(linkedNode))
|
|
212
|
+
lookup[name].push(linkedNode);
|
|
215
213
|
break;
|
|
216
214
|
|
|
217
215
|
default:
|
|
@@ -254,14 +252,23 @@ module.exports = function (RED)
|
|
|
254
252
|
return message;
|
|
255
253
|
}
|
|
256
254
|
|
|
257
|
-
let performAction = (mode, action, affectedNodes) =>
|
|
255
|
+
let performAction = (mode, action, number, affectedNodes) =>
|
|
258
256
|
{
|
|
259
257
|
if (action != null && affectedNodes.length > 0)
|
|
260
258
|
{
|
|
261
259
|
for (const node of affectedNodes)
|
|
262
260
|
{
|
|
263
261
|
// node.log("Notify node " + node.id);
|
|
264
|
-
|
|
262
|
+
if (action == "position")
|
|
263
|
+
{
|
|
264
|
+
// console.log({ "topic": action, "payload": number });
|
|
265
|
+
if (number != null)
|
|
266
|
+
RED.events.emit("node:" + node.id, { "topic": action, "payload": number });
|
|
267
|
+
}
|
|
268
|
+
else
|
|
269
|
+
{
|
|
270
|
+
RED.events.emit("node:" + node.id, { "topic": action });
|
|
271
|
+
}
|
|
265
272
|
}
|
|
266
273
|
|
|
267
274
|
log.actions.push({ mode, action, nodes: affectedNodes.map(n => n.name || n.id) });
|