node-red-contrib-dmx-for-ha 0.1.4 → 0.1.6

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.
@@ -14,28 +14,13 @@
14
14
  outputs: 0,
15
15
  inputLabels: ['Input'],
16
16
  button: {
17
- cancel: {
18
- label: 'Remove',
19
- onclick: function() {
20
- var self = this;
21
- $.ajax({
22
- url: 'ha-mqtt-button/' + this.id + '/remove',
23
- type: 'POST',
24
- success: function() { RED.notify('device:remove sent', 'success'); },
25
- error: function() { RED.notify('Error sending remove', 'error'); }
26
- });
27
- }
28
- },
29
- confirm: {
30
- label: 'Add',
31
- onclick: function() {
32
- $.ajax({
33
- url: 'ha-mqtt-button/' + this.id + '/add',
34
- type: 'POST',
35
- success: function() { RED.notify('device:add sent', 'success'); },
36
- error: function() { RED.notify('Error sending add', 'error'); }
37
- });
38
- }
17
+ onclick: function() {
18
+ $.ajax({
19
+ url: 'ha-mqtt-button/' + this.id + '/add',
20
+ type: 'POST',
21
+ success: function() { RED.notify('device:add sent','success'); },
22
+ error: function() { RED.notify('Error check NR log','error'); }
23
+ });
39
24
  }
40
25
  },
41
26
  paletteLabel: 'Button',
@@ -37,18 +37,6 @@ module.exports = function (RED) {
37
37
  autoDiscover();
38
38
  });
39
39
 
40
- // ── HTTP endpoints for canvas buttons ─────────────────────────
41
- RED.httpAdmin.post('/ha-mqtt-button/:id/add', RED.auth.needsPermission('ha-mqtt-button.write'), function(req, res) {
42
- const n = RED.nodes.getNode(req.params.id);
43
- if (n) { n.receive({ device: 'add' }); res.sendStatus(200); }
44
- else res.sendStatus(404);
45
- });
46
-
47
- RED.httpAdmin.post('/ha-mqtt-button/:id/remove', RED.auth.needsPermission('ha-mqtt-button.write'), function(req, res) {
48
- const n = RED.nodes.getNode(req.params.id);
49
- if (n) { n.receive({ device: 'remove' }); res.sendStatus(200); }
50
- else res.sendStatus(404);
51
- });
52
40
 
53
41
 
54
42
 
@@ -189,5 +177,19 @@ module.exports = function (RED) {
189
177
  });
190
178
  }
191
179
 
180
+
181
+ // ── HTTP endpoints for canvas buttons — registered once at module level ──
182
+ RED.httpAdmin.post('/ha-mqtt-button/:id/add', RED.auth.needsPermission('ha-mqtt-button.write'), function(req, res) {
183
+ const n = RED.nodes.getNode(req.params.id);
184
+ if (n) { n.receive({ device: 'add' }); res.sendStatus(200); }
185
+ else res.sendStatus(404);
186
+ });
187
+
188
+ RED.httpAdmin.post('/ha-mqtt-button/:id/remove', RED.auth.needsPermission('ha-mqtt-button.write'), function(req, res) {
189
+ const n = RED.nodes.getNode(req.params.id);
190
+ if (n) { n.receive({ device: 'remove' }); res.sendStatus(200); }
191
+ else res.sendStatus(404);
192
+ });
193
+
192
194
  RED.nodes.registerType('ha-mqtt-button', HaMqttButtonNode);
193
195
  };
@@ -15,28 +15,13 @@
15
15
  outputLabels: ['Link'],
16
16
  inputLabels: ['Input'],
17
17
  button: {
18
- cancel: {
19
- label: 'Remove',
20
- onclick: function() {
21
- var self = this;
22
- $.ajax({
23
- url: 'ha-mqtt-dmx-group/' + this.id + '/remove',
24
- type: 'POST',
25
- success: function() { RED.notify('device:remove sent', 'success'); },
26
- error: function() { RED.notify('Error sending remove', 'error'); }
27
- });
28
- }
29
- },
30
- confirm: {
31
- label: 'Add',
32
- onclick: function() {
33
- $.ajax({
34
- url: 'ha-mqtt-dmx-group/' + this.id + '/add',
35
- type: 'POST',
36
- success: function() { RED.notify('device:add sent', 'success'); },
37
- error: function() { RED.notify('Error sending add', 'error'); }
38
- });
39
- }
18
+ onclick: function() {
19
+ $.ajax({
20
+ url: 'ha-mqtt-dmx-group/' + this.id + '/add',
21
+ type: 'POST',
22
+ success: function() { RED.notify('device:add sent','success'); },
23
+ error: function() { RED.notify('Error check NR log','error'); }
24
+ });
40
25
  }
41
26
  },
42
27
  paletteLabel: 'DMX Group',
@@ -40,18 +40,6 @@ module.exports = function (RED) {
40
40
  autoDiscover();
41
41
  });
42
42
 
43
- // ── HTTP endpoints for canvas buttons ─────────────────────────
44
- RED.httpAdmin.post('/ha-mqtt-dmx-group/:id/add', RED.auth.needsPermission('ha-mqtt-dmx-group.write'), function(req, res) {
45
- const n = RED.nodes.getNode(req.params.id);
46
- if (n) { n.receive({ device: 'add' }); res.sendStatus(200); }
47
- else res.sendStatus(404);
48
- });
49
-
50
- RED.httpAdmin.post('/ha-mqtt-dmx-group/:id/remove', RED.auth.needsPermission('ha-mqtt-dmx-group.write'), function(req, res) {
51
- const n = RED.nodes.getNode(req.params.id);
52
- if (n) { n.receive({ device: 'remove' }); res.sendStatus(200); }
53
- else res.sendStatus(404);
54
- });
55
43
 
56
44
 
57
45
 
@@ -85,12 +73,19 @@ module.exports = function (RED) {
85
73
  const cmdTopic = `${groupTopic}/${cfg.commandTopic}`;
86
74
 
87
75
  // ── Context helpers ───────────────────────────────────────
76
+ // Check disk store available once on startup
77
+ let diskAvailable = false;
78
+ try { node.context().get('__test', 'disk'); diskAvailable = true; }
79
+ catch(e) { diskAvailable = false; }
80
+
88
81
  function ctxGet(key, store) {
89
- try { return node.context().get(key, store); }
82
+ if (store === 'disk' && !diskAvailable) return node.context().get(key);
83
+ try { return node.context().get(key, store || undefined); }
90
84
  catch(e) { return node.context().get(key); }
91
85
  }
92
86
  function ctxSet(key, val, store) {
93
- try { node.context().set(key, val, store); }
87
+ if (store === 'disk' && !diskAvailable) { node.context().set(key, val); return; }
88
+ try { node.context().set(key, val, store || undefined); }
94
89
  catch(e) { node.context().set(key, val); }
95
90
  }
96
91
  function recall(ramKey, diskKey, fallback) {
@@ -296,5 +291,19 @@ module.exports = function (RED) {
296
291
  });
297
292
  }
298
293
 
294
+
295
+ // ── HTTP endpoints for canvas buttons — registered once at module level ──
296
+ RED.httpAdmin.post('/ha-mqtt-dmx-group/:id/add', RED.auth.needsPermission('ha-mqtt-dmx-group.write'), function(req, res) {
297
+ const n = RED.nodes.getNode(req.params.id);
298
+ if (n) { n.receive({ device: 'add' }); res.sendStatus(200); }
299
+ else res.sendStatus(404);
300
+ });
301
+
302
+ RED.httpAdmin.post('/ha-mqtt-dmx-group/:id/remove', RED.auth.needsPermission('ha-mqtt-dmx-group.write'), function(req, res) {
303
+ const n = RED.nodes.getNode(req.params.id);
304
+ if (n) { n.receive({ device: 'remove' }); res.sendStatus(200); }
305
+ else res.sendStatus(404);
306
+ });
307
+
299
308
  RED.nodes.registerType('ha-mqtt-dmx-group', HaMqttDmxGroupNode);
300
309
  };
@@ -123,28 +123,13 @@
123
123
  inputs: 1,
124
124
  outputs: 0,
125
125
  button: {
126
- cancel: {
127
- label: 'Remove',
128
- onclick: function() {
129
- var self = this;
130
- $.ajax({
131
- url: 'ha-mqtt-dmx/' + this.id + '/remove',
132
- type: 'POST',
133
- success: function() { RED.notify('device:remove sent', 'success'); },
134
- error: function() { RED.notify('Error sending remove', 'error'); }
135
- });
136
- }
137
- },
138
- confirm: {
139
- label: 'Add',
140
- onclick: function() {
141
- $.ajax({
142
- url: 'ha-mqtt-dmx/' + this.id + '/add',
143
- type: 'POST',
144
- success: function() { RED.notify('device:add sent', 'success'); },
145
- error: function() { RED.notify('Error sending add', 'error'); }
146
- });
147
- }
126
+ onclick: function() {
127
+ $.ajax({
128
+ url: 'ha-mqtt-dmx/' + this.id + '/add',
129
+ type: 'POST',
130
+ success: function() { RED.notify('device:add sent','success'); },
131
+ error: function() { RED.notify('Error check NR log','error'); }
132
+ });
148
133
  }
149
134
  },
150
135
  paletteLabel: 'DMX',
@@ -47,18 +47,6 @@ module.exports = function (RED) {
47
47
  autoDiscover();
48
48
  });
49
49
 
50
- // ── HTTP endpoints for canvas buttons ─────────────────────────
51
- RED.httpAdmin.post('/ha-mqtt-dmx/:id/add', RED.auth.needsPermission('ha-mqtt-dmx.write'), function(req, res) {
52
- const n = RED.nodes.getNode(req.params.id);
53
- if (n) { n.receive({ device: 'add' }); res.sendStatus(200); }
54
- else res.sendStatus(404);
55
- });
56
-
57
- RED.httpAdmin.post('/ha-mqtt-dmx/:id/remove', RED.auth.needsPermission('ha-mqtt-dmx.write'), function(req, res) {
58
- const n = RED.nodes.getNode(req.params.id);
59
- if (n) { n.receive({ device: 'remove' }); res.sendStatus(200); }
60
- else res.sendStatus(404);
61
- });
62
50
 
63
51
 
64
52
 
@@ -106,12 +94,19 @@ module.exports = function (RED) {
106
94
  const dmxTopic = `${cfg.siteId}/${cfg.zone}/dmx/${S.universe}`;
107
95
 
108
96
  // ── Context helpers ───────────────────────────────────────
97
+ // Check disk store available once on startup
98
+ let diskAvailable = false;
99
+ try { node.context().get('__test', 'disk'); diskAvailable = true; }
100
+ catch(e) { diskAvailable = false; }
101
+
109
102
  function ctxGet(key, store) {
110
- try { return node.context().get(key, store); }
103
+ if (store === 'disk' && !diskAvailable) return node.context().get(key);
104
+ try { return node.context().get(key, store || undefined); }
111
105
  catch(e) { return node.context().get(key); }
112
106
  }
113
107
  function ctxSet(key, val, store) {
114
- try { node.context().set(key, val, store); }
108
+ if (store === 'disk' && !diskAvailable) { node.context().set(key, val); return; }
109
+ try { node.context().set(key, val, store || undefined); }
115
110
  catch(e) { node.context().set(key, val); }
116
111
  }
117
112
  function recall(ramKey, diskKey, fallback) {
@@ -568,5 +563,19 @@ module.exports = function (RED) {
568
563
  });
569
564
  }
570
565
 
566
+
567
+ // ── HTTP endpoints for canvas buttons — registered once at module level ──
568
+ RED.httpAdmin.post('/ha-mqtt-dmx/:id/add', RED.auth.needsPermission('ha-mqtt-dmx.write'), function(req, res) {
569
+ const n = RED.nodes.getNode(req.params.id);
570
+ if (n) { n.receive({ device: 'add' }); res.sendStatus(200); }
571
+ else res.sendStatus(404);
572
+ });
573
+
574
+ RED.httpAdmin.post('/ha-mqtt-dmx/:id/remove', RED.auth.needsPermission('ha-mqtt-dmx.write'), function(req, res) {
575
+ const n = RED.nodes.getNode(req.params.id);
576
+ if (n) { n.receive({ device: 'remove' }); res.sendStatus(200); }
577
+ else res.sendStatus(404);
578
+ });
579
+
571
580
  RED.nodes.registerType('ha-mqtt-dmx', HaMqttDmxNode);
572
581
  };
@@ -14,28 +14,13 @@
14
14
  outputs: 0,
15
15
  inputLabels: ['Input'],
16
16
  button: {
17
- cancel: {
18
- label: 'Remove',
19
- onclick: function() {
20
- var self = this;
21
- $.ajax({
22
- url: 'ha-mqtt-pir/' + this.id + '/remove',
23
- type: 'POST',
24
- success: function() { RED.notify('device:remove sent', 'success'); },
25
- error: function() { RED.notify('Error sending remove', 'error'); }
26
- });
27
- }
28
- },
29
- confirm: {
30
- label: 'Add',
31
- onclick: function() {
32
- $.ajax({
33
- url: 'ha-mqtt-pir/' + this.id + '/add',
34
- type: 'POST',
35
- success: function() { RED.notify('device:add sent', 'success'); },
36
- error: function() { RED.notify('Error sending add', 'error'); }
37
- });
38
- }
17
+ onclick: function() {
18
+ $.ajax({
19
+ url: 'ha-mqtt-pir/' + this.id + '/add',
20
+ type: 'POST',
21
+ success: function() { RED.notify('device:add sent','success'); },
22
+ error: function() { RED.notify('Error check NR log','error'); }
23
+ });
39
24
  }
40
25
  },
41
26
  paletteLabel: 'PIR',
@@ -37,18 +37,6 @@ module.exports = function (RED) {
37
37
  autoDiscover();
38
38
  });
39
39
 
40
- // ── HTTP endpoints for canvas buttons ─────────────────────────
41
- RED.httpAdmin.post('/ha-mqtt-pir/:id/add', RED.auth.needsPermission('ha-mqtt-pir.write'), function(req, res) {
42
- const n = RED.nodes.getNode(req.params.id);
43
- if (n) { n.receive({ device: 'add' }); res.sendStatus(200); }
44
- else res.sendStatus(404);
45
- });
46
-
47
- RED.httpAdmin.post('/ha-mqtt-pir/:id/remove', RED.auth.needsPermission('ha-mqtt-pir.write'), function(req, res) {
48
- const n = RED.nodes.getNode(req.params.id);
49
- if (n) { n.receive({ device: 'remove' }); res.sendStatus(200); }
50
- else res.sendStatus(404);
51
- });
52
40
 
53
41
 
54
42
 
@@ -214,5 +202,19 @@ module.exports = function (RED) {
214
202
  });
215
203
  }
216
204
 
205
+
206
+ // ── HTTP endpoints for canvas buttons — registered once at module level ──
207
+ RED.httpAdmin.post('/ha-mqtt-pir/:id/add', RED.auth.needsPermission('ha-mqtt-pir.write'), function(req, res) {
208
+ const n = RED.nodes.getNode(req.params.id);
209
+ if (n) { n.receive({ device: 'add' }); res.sendStatus(200); }
210
+ else res.sendStatus(404);
211
+ });
212
+
213
+ RED.httpAdmin.post('/ha-mqtt-pir/:id/remove', RED.auth.needsPermission('ha-mqtt-pir.write'), function(req, res) {
214
+ const n = RED.nodes.getNode(req.params.id);
215
+ if (n) { n.receive({ device: 'remove' }); res.sendStatus(200); }
216
+ else res.sendStatus(404);
217
+ });
218
+
217
219
  RED.nodes.registerType('ha-mqtt-pir', HaMqttPirNode);
218
220
  };
@@ -14,28 +14,13 @@
14
14
  outputs: 0,
15
15
  inputLabels: ['Input'],
16
16
  button: {
17
- cancel: {
18
- label: 'Remove',
19
- onclick: function() {
20
- var self = this;
21
- $.ajax({
22
- url: 'ha-mqtt-relay/' + this.id + '/remove',
23
- type: 'POST',
24
- success: function() { RED.notify('device:remove sent', 'success'); },
25
- error: function() { RED.notify('Error sending remove', 'error'); }
26
- });
27
- }
28
- },
29
- confirm: {
30
- label: 'Add',
31
- onclick: function() {
32
- $.ajax({
33
- url: 'ha-mqtt-relay/' + this.id + '/add',
34
- type: 'POST',
35
- success: function() { RED.notify('device:add sent', 'success'); },
36
- error: function() { RED.notify('Error sending add', 'error'); }
37
- });
38
- }
17
+ onclick: function() {
18
+ $.ajax({
19
+ url: 'ha-mqtt-relay/' + this.id + '/add',
20
+ type: 'POST',
21
+ success: function() { RED.notify('device:add sent','success'); },
22
+ error: function() { RED.notify('Error check NR log','error'); }
23
+ });
39
24
  }
40
25
  },
41
26
  paletteLabel: 'Relay',
@@ -40,18 +40,6 @@ module.exports = function (RED) {
40
40
  autoDiscover();
41
41
  });
42
42
 
43
- // ── HTTP endpoints for canvas buttons ─────────────────────────
44
- RED.httpAdmin.post('/ha-mqtt-relay/:id/add', RED.auth.needsPermission('ha-mqtt-relay.write'), function(req, res) {
45
- const n = RED.nodes.getNode(req.params.id);
46
- if (n) { n.receive({ device: 'add' }); res.sendStatus(200); }
47
- else res.sendStatus(404);
48
- });
49
-
50
- RED.httpAdmin.post('/ha-mqtt-relay/:id/remove', RED.auth.needsPermission('ha-mqtt-relay.write'), function(req, res) {
51
- const n = RED.nodes.getNode(req.params.id);
52
- if (n) { n.receive({ device: 'remove' }); res.sendStatus(200); }
53
- else res.sendStatus(404);
54
- });
55
43
 
56
44
 
57
45
 
@@ -86,12 +74,19 @@ module.exports = function (RED) {
86
74
  const relayTopic = `${cfg.siteId}/${cfg.zone}/${S.controllerNum}/${S.mqttSegment}/${S.relayNum}`;
87
75
 
88
76
  // ── Context helpers ───────────────────────────────────────
77
+ // Check disk store available once on startup
78
+ let diskAvailable = false;
79
+ try { node.context().get('__test', 'disk'); diskAvailable = true; }
80
+ catch(e) { diskAvailable = false; }
81
+
89
82
  function ctxGet(key, store) {
90
- try { return node.context().get(key, store); }
83
+ if (store === 'disk' && !diskAvailable) return node.context().get(key);
84
+ try { return node.context().get(key, store || undefined); }
91
85
  catch(e) { return node.context().get(key); }
92
86
  }
93
87
  function ctxSet(key, val, store) {
94
- try { node.context().set(key, val, store); }
88
+ if (store === 'disk' && !diskAvailable) { node.context().set(key, val); return; }
89
+ try { node.context().set(key, val, store || undefined); }
95
90
  catch(e) { node.context().set(key, val); }
96
91
  }
97
92
  function recall(ramKey, diskKey, fallback) {
@@ -320,5 +315,19 @@ module.exports = function (RED) {
320
315
  });
321
316
  }
322
317
 
318
+
319
+ // ── HTTP endpoints for canvas buttons — registered once at module level ──
320
+ RED.httpAdmin.post('/ha-mqtt-relay/:id/add', RED.auth.needsPermission('ha-mqtt-relay.write'), function(req, res) {
321
+ const n = RED.nodes.getNode(req.params.id);
322
+ if (n) { n.receive({ device: 'add' }); res.sendStatus(200); }
323
+ else res.sendStatus(404);
324
+ });
325
+
326
+ RED.httpAdmin.post('/ha-mqtt-relay/:id/remove', RED.auth.needsPermission('ha-mqtt-relay.write'), function(req, res) {
327
+ const n = RED.nodes.getNode(req.params.id);
328
+ if (n) { n.receive({ device: 'remove' }); res.sendStatus(200); }
329
+ else res.sendStatus(404);
330
+ });
331
+
323
332
  RED.nodes.registerType('ha-mqtt-relay', HaMqttRelayNode);
324
333
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-dmx-for-ha",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "DMX lighting control for Home Assistant via Node-RED and MQTT. Place a node, fill in the settings, deploy. Full HA device registry integration with RGBW/RGBWW/CCT/brightness colour modes, transitions, effects, and group control.",
5
5
  "keywords": [
6
6
  "node-red",