smart-nodes 0.1.0

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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +127 -0
  4. package/central/central.html +328 -0
  5. package/central/central.js +95 -0
  6. package/compare/compare.html +137 -0
  7. package/compare/compare.js +151 -0
  8. package/delay/delay.html +192 -0
  9. package/delay/delay.js +175 -0
  10. package/examples/central.json +804 -0
  11. package/examples/central.png +0 -0
  12. package/examples/compare.json +916 -0
  13. package/examples/compare.png +0 -0
  14. package/examples/delay.json +198 -0
  15. package/examples/delay.png +0 -0
  16. package/examples/forwarder.json +152 -0
  17. package/examples/forwarder.png +0 -0
  18. package/examples/hysteresis.json +358 -0
  19. package/examples/hysteresis.png +0 -0
  20. package/examples/light-control.json +499 -0
  21. package/examples/light-control.png +0 -0
  22. package/examples/logic.json +562 -0
  23. package/examples/logic.png +0 -0
  24. package/examples/long-press-control.json +113 -0
  25. package/examples/long-press-control.png +0 -0
  26. package/examples/multi-press-control.json +136 -0
  27. package/examples/multi-press-control.png +0 -0
  28. package/examples/scene-control.json +535 -0
  29. package/examples/scene-control.png +0 -0
  30. package/examples/scheduler.json +164 -0
  31. package/examples/scheduler.png +0 -0
  32. package/examples/shutter-complex-control.json +489 -0
  33. package/examples/shutter-complex-control.png +0 -0
  34. package/examples/shutter-control.json +457 -0
  35. package/examples/shutter-control.png +0 -0
  36. package/examples/statistic.json +1112 -0
  37. package/examples/statistic.png +0 -0
  38. package/forwarder/forwarder.html +100 -0
  39. package/forwarder/forwarder.js +95 -0
  40. package/hysteresis/hysteresis.html +152 -0
  41. package/hysteresis/hysteresis.js +146 -0
  42. package/light-control/light-control.html +358 -0
  43. package/light-control/light-control.js +231 -0
  44. package/logic/logic.html +168 -0
  45. package/logic/logic.js +171 -0
  46. package/long-press-control/long-press-control.html +74 -0
  47. package/long-press-control/long-press-control.js +75 -0
  48. package/multi-press-control/multi-press-control.html +135 -0
  49. package/multi-press-control/multi-press-control.js +68 -0
  50. package/package.json +59 -0
  51. package/persistence.js +74 -0
  52. package/scene-control/scene-control.html +575 -0
  53. package/scene-control/scene-control.js +265 -0
  54. package/scheduler/scheduler.html +338 -0
  55. package/scheduler/scheduler.js +209 -0
  56. package/shutter-complex-control/shutter-complex-control.html +330 -0
  57. package/shutter-complex-control/shutter-complex-control.js +399 -0
  58. package/shutter-control/shutter-control.html +283 -0
  59. package/shutter-control/shutter-control.js +208 -0
  60. package/smart_helper.js +156 -0
  61. package/statistic/statistic.html +107 -0
  62. package/statistic/statistic.js +196 -0
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "smart-nodes",
3
+ "version": "0.1.0",
4
+ "description": "Smart Nodes",
5
+ "keywords": [
6
+ "node-red",
7
+ "smart nodes",
8
+ "light control",
9
+ "shutter control",
10
+ "long press",
11
+ "multi press",
12
+ "scene",
13
+ "scenes",
14
+ "delay",
15
+ "forwarder",
16
+ "logic",
17
+ "hysteresis",
18
+ "compare",
19
+ "comparator",
20
+ "statistic",
21
+ "scheduler",
22
+ "central"
23
+ ],
24
+ "scripts": {
25
+ "test": "echo \"Error: no test specified\" && exit 1"
26
+ },
27
+ "author": "Samuel Bergen",
28
+ "license": "MIT",
29
+ "node-red": {
30
+ "version": ">=1.0.0",
31
+ "nodes": {
32
+ "light-control": "light-control/light-control.js",
33
+ "scene-control": "scene-control/scene-control.js",
34
+ "shutter-control": "shutter-control/shutter-control.js",
35
+ "shutter-complex-control": "shutter-complex-control/shutter-complex-control.js",
36
+ "long-press-control": "long-press-control/long-press-control.js",
37
+ "multi-press-control": "multi-press-control/multi-press-control.js",
38
+ "logic": "logic/logic.js",
39
+ "forwarder": "forwarder/forwarder.js",
40
+ "compare": "compare/compare.js",
41
+ "hysteresis": "hysteresis/hysteresis.js",
42
+ "statistic": "statistic/statistic.js",
43
+ "scheduler": "scheduler/scheduler.js",
44
+ "delay": "delay/delay.js",
45
+ "central": "central/central.js"
46
+ }
47
+ },
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "https://github.com/TODO"
51
+ },
52
+ "dependencies": {},
53
+ "devDependencies": {
54
+ "font-awesome": "^4.7.0"
55
+ },
56
+ "engines": {
57
+ "node": ">=10"
58
+ }
59
+ }
package/persistence.js ADDED
@@ -0,0 +1,74 @@
1
+ let instance = null;
2
+
3
+ module.exports = function (_RED)
4
+ {
5
+ if (instance != null)
6
+ return instance;
7
+
8
+ let RED = _RED;
9
+ let hasChanges = false;
10
+
11
+ const fs = require('fs');
12
+ const path = RED.settings.userDir + '/SmartNodesContext.json';
13
+
14
+ let globalData = {};
15
+
16
+ if (fs.existsSync(path))
17
+ {
18
+ try
19
+ {
20
+ let fileContent = fs.readFileSync(path, "utf8");
21
+ globalData = Object.assign({}, JSON.parse(fileContent));
22
+ // console.log("Loaded " + Object.keys(globalData).length + " smart_nodes config items");
23
+ }
24
+ catch (error)
25
+ {
26
+ console.error("Couldn't read SmartNodesContext.json", error);
27
+ }
28
+ }
29
+
30
+ // Autosave each 10 seconds if changes exists.
31
+ let interval = setInterval(() =>
32
+ {
33
+ if (hasChanges)
34
+ save();
35
+
36
+ }, 10 * 1000);
37
+
38
+ function save()
39
+ {
40
+ try
41
+ {
42
+ // console.log("Auto save");
43
+ fs.writeFile(path, JSON.stringify(globalData), err =>
44
+ {
45
+ if (err)
46
+ console.error(err);
47
+ });
48
+ hasChanges = false;
49
+ }
50
+ catch (error)
51
+ {
52
+ console.error("Couldn't write SmartNodesContext.json", error);
53
+ }
54
+ }
55
+
56
+ function set(id, data)
57
+ {
58
+ hasChanges = true;
59
+ globalData["id" + id] = data;
60
+ }
61
+
62
+ function get(id)
63
+ {
64
+ return globalData["id" + id];
65
+ }
66
+
67
+ function del(id)
68
+ {
69
+ delete globalData["id" + id];
70
+ }
71
+
72
+ instance = { set, get, del };
73
+ return instance;
74
+ };