smart-nodes 0.3.6 → 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 +24 -24
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
|
{
|
|
@@ -131,7 +128,7 @@ module.exports = function (RED)
|
|
|
131
128
|
|
|
132
129
|
case "und":
|
|
133
130
|
case "and":
|
|
134
|
-
if (performAction(mode, action, affectedNodes))
|
|
131
|
+
if (performAction(mode, action, number, affectedNodes))
|
|
135
132
|
{
|
|
136
133
|
action = null;
|
|
137
134
|
affectedNodes = [];
|
|
@@ -147,24 +144,26 @@ module.exports = function (RED)
|
|
|
147
144
|
let room = rooms[parseInt(word.substring(1), 10)];
|
|
148
145
|
// node.log("Found room " + room);
|
|
149
146
|
|
|
150
|
-
if (lookup[
|
|
147
|
+
if (lookup[room] && Array.isArray(lookup[room]))
|
|
151
148
|
{
|
|
152
|
-
for (const node of lookup[
|
|
149
|
+
for (const node of lookup[room])
|
|
153
150
|
{
|
|
154
151
|
if (!affectedNodes.includes(node))
|
|
155
152
|
affectedNodes.push(node);
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
155
|
}
|
|
159
|
-
else if (
|
|
156
|
+
else if (isFinite(word))
|
|
160
157
|
{
|
|
161
158
|
number = parseInt(word, 10);
|
|
159
|
+
// node.log("Found number " + number);
|
|
162
160
|
}
|
|
163
|
-
else if (word[word.length - 1] == "%" &&
|
|
161
|
+
else if (word[word.length - 1] == "%" && isFinite(word.substr(0, word.length - 1)))
|
|
164
162
|
{
|
|
165
163
|
number = parseInt(word.substr(0, word.length - 1), 10);
|
|
166
164
|
mode = "shutter";
|
|
167
165
|
action = "position";
|
|
166
|
+
// node.log("Found number " + number + " with %");
|
|
168
167
|
}
|
|
169
168
|
else
|
|
170
169
|
{
|
|
@@ -174,7 +173,7 @@ module.exports = function (RED)
|
|
|
174
173
|
}
|
|
175
174
|
}
|
|
176
175
|
|
|
177
|
-
performAction(mode, action, affectedNodes);
|
|
176
|
+
performAction(mode, action, number, affectedNodes);
|
|
178
177
|
|
|
179
178
|
// node.log("Finished");
|
|
180
179
|
// node.log(log);
|
|
@@ -203,22 +202,14 @@ module.exports = function (RED)
|
|
|
203
202
|
{
|
|
204
203
|
case "smart_light-control":
|
|
205
204
|
case "smart_scene-control":
|
|
206
|
-
// node.log("Add room " + name);
|
|
207
|
-
if (!lookup.light[name])
|
|
208
|
-
lookup.light[name] = [];
|
|
209
|
-
|
|
210
|
-
if (!lookup.light[name].includes(linkedNode))
|
|
211
|
-
lookup.light[name].push(linkedNode);
|
|
212
|
-
break;
|
|
213
|
-
|
|
214
205
|
case "smart_shutter-control":
|
|
215
206
|
case "smart_shutter-complex-control":
|
|
216
207
|
// node.log("Add room " + name);
|
|
217
|
-
if (!lookup
|
|
218
|
-
lookup
|
|
208
|
+
if (!lookup[name])
|
|
209
|
+
lookup[name] = [];
|
|
219
210
|
|
|
220
|
-
if (!lookup
|
|
221
|
-
lookup
|
|
211
|
+
if (!lookup[name].includes(linkedNode))
|
|
212
|
+
lookup[name].push(linkedNode);
|
|
222
213
|
break;
|
|
223
214
|
|
|
224
215
|
default:
|
|
@@ -261,14 +252,23 @@ module.exports = function (RED)
|
|
|
261
252
|
return message;
|
|
262
253
|
}
|
|
263
254
|
|
|
264
|
-
let performAction = (mode, action, affectedNodes) =>
|
|
255
|
+
let performAction = (mode, action, number, affectedNodes) =>
|
|
265
256
|
{
|
|
266
257
|
if (action != null && affectedNodes.length > 0)
|
|
267
258
|
{
|
|
268
259
|
for (const node of affectedNodes)
|
|
269
260
|
{
|
|
270
261
|
// node.log("Notify node " + node.id);
|
|
271
|
-
|
|
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
|
+
}
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
log.actions.push({ mode, action, nodes: affectedNodes.map(n => n.name || n.id) });
|