smart-nodes 0.3.6 → 0.3.9
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 +42 -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
|
{
|
|
@@ -82,6 +79,12 @@ module.exports = function (RED)
|
|
|
82
79
|
// node.log("Set action to on");
|
|
83
80
|
mode = "light";
|
|
84
81
|
action = "on";
|
|
82
|
+
if (performAction(mode, action, number, affectedNodes))
|
|
83
|
+
{
|
|
84
|
+
action = null;
|
|
85
|
+
affectedNodes = [];
|
|
86
|
+
number = null;
|
|
87
|
+
}
|
|
85
88
|
break;
|
|
86
89
|
|
|
87
90
|
case "aus":
|
|
@@ -90,6 +93,12 @@ module.exports = function (RED)
|
|
|
90
93
|
// node.log("Set action to off");
|
|
91
94
|
mode = "light";
|
|
92
95
|
action = "off";
|
|
96
|
+
if (performAction(mode, action, number, affectedNodes))
|
|
97
|
+
{
|
|
98
|
+
action = null;
|
|
99
|
+
affectedNodes = [];
|
|
100
|
+
number = null;
|
|
101
|
+
}
|
|
93
102
|
break;
|
|
94
103
|
|
|
95
104
|
case "hoch":
|
|
@@ -131,7 +140,7 @@ module.exports = function (RED)
|
|
|
131
140
|
|
|
132
141
|
case "und":
|
|
133
142
|
case "and":
|
|
134
|
-
if (performAction(mode, action, affectedNodes))
|
|
143
|
+
if (performAction(mode, action, number, affectedNodes))
|
|
135
144
|
{
|
|
136
145
|
action = null;
|
|
137
146
|
affectedNodes = [];
|
|
@@ -147,24 +156,26 @@ module.exports = function (RED)
|
|
|
147
156
|
let room = rooms[parseInt(word.substring(1), 10)];
|
|
148
157
|
// node.log("Found room " + room);
|
|
149
158
|
|
|
150
|
-
if (lookup[
|
|
159
|
+
if (lookup[room] && Array.isArray(lookup[room]))
|
|
151
160
|
{
|
|
152
|
-
for (const node of lookup[
|
|
161
|
+
for (const node of lookup[room])
|
|
153
162
|
{
|
|
154
163
|
if (!affectedNodes.includes(node))
|
|
155
164
|
affectedNodes.push(node);
|
|
156
165
|
}
|
|
157
166
|
}
|
|
158
167
|
}
|
|
159
|
-
else if (
|
|
168
|
+
else if (isFinite(word))
|
|
160
169
|
{
|
|
161
170
|
number = parseInt(word, 10);
|
|
171
|
+
// node.log("Found number " + number);
|
|
162
172
|
}
|
|
163
|
-
else if (word[word.length - 1] == "%" &&
|
|
173
|
+
else if (word[word.length - 1] == "%" && isFinite(word.substr(0, word.length - 1)))
|
|
164
174
|
{
|
|
165
175
|
number = parseInt(word.substr(0, word.length - 1), 10);
|
|
166
176
|
mode = "shutter";
|
|
167
177
|
action = "position";
|
|
178
|
+
// node.log("Found number " + number + " with %");
|
|
168
179
|
}
|
|
169
180
|
else
|
|
170
181
|
{
|
|
@@ -174,7 +185,7 @@ module.exports = function (RED)
|
|
|
174
185
|
}
|
|
175
186
|
}
|
|
176
187
|
|
|
177
|
-
performAction(mode, action, affectedNodes);
|
|
188
|
+
performAction(mode, action, number, affectedNodes);
|
|
178
189
|
|
|
179
190
|
// node.log("Finished");
|
|
180
191
|
// node.log(log);
|
|
@@ -203,22 +214,14 @@ module.exports = function (RED)
|
|
|
203
214
|
{
|
|
204
215
|
case "smart_light-control":
|
|
205
216
|
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
217
|
case "smart_shutter-control":
|
|
215
218
|
case "smart_shutter-complex-control":
|
|
216
219
|
// node.log("Add room " + name);
|
|
217
|
-
if (!lookup
|
|
218
|
-
lookup
|
|
220
|
+
if (!lookup[name])
|
|
221
|
+
lookup[name] = [];
|
|
219
222
|
|
|
220
|
-
if (!lookup
|
|
221
|
-
lookup
|
|
223
|
+
if (!lookup[name].includes(linkedNode))
|
|
224
|
+
lookup[name].push(linkedNode);
|
|
222
225
|
break;
|
|
223
226
|
|
|
224
227
|
default:
|
|
@@ -261,14 +264,29 @@ module.exports = function (RED)
|
|
|
261
264
|
return message;
|
|
262
265
|
}
|
|
263
266
|
|
|
264
|
-
let performAction = (mode, action, affectedNodes) =>
|
|
267
|
+
let performAction = (mode, action, number, affectedNodes) =>
|
|
265
268
|
{
|
|
266
269
|
if (action != null && affectedNodes.length > 0)
|
|
267
270
|
{
|
|
268
271
|
for (const node of affectedNodes)
|
|
269
272
|
{
|
|
273
|
+
if (mode == "light" && !["smart_light-control", "smart_scene-control"].includes(node.type))
|
|
274
|
+
continue;
|
|
275
|
+
|
|
276
|
+
if (mode == "shutter" && !["smart_shutter-control", "smart_shutter-complex-control"].includes(node.type))
|
|
277
|
+
continue;
|
|
278
|
+
|
|
270
279
|
// node.log("Notify node " + node.id);
|
|
271
|
-
|
|
280
|
+
if (action == "position")
|
|
281
|
+
{
|
|
282
|
+
// console.log({ "topic": action, "payload": number });
|
|
283
|
+
if (number != null)
|
|
284
|
+
RED.events.emit("node:" + node.id, { "topic": action, "payload": number });
|
|
285
|
+
}
|
|
286
|
+
else
|
|
287
|
+
{
|
|
288
|
+
RED.events.emit("node:" + node.id, { "topic": action });
|
|
289
|
+
}
|
|
272
290
|
}
|
|
273
291
|
|
|
274
292
|
log.actions.push({ mode, action, nodes: affectedNodes.map(n => n.name || n.id) });
|