node-red-contrib-huemagic 5.2.0 → 5.2.1

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/CHANGELOG.md CHANGED
@@ -2,7 +2,22 @@
2
2
 
3
3
  # Changelog
4
4
 
5
- ### v5.2.0 (latest)
5
+ ### v5.2.1 (latest)
6
+
7
+ **Fixes**
8
+
9
+ * The scene search of the "Hue Scene" node says "Searching scenes…" again instead of showing the raw text `hue-rules.config.searching` ([#458](https://github.com/Foddy/node-red-contrib-huemagic/issues/458)) (thx @JGoor)
10
+ * When a search for lights, groups, scenes, sensors, rules or automations in the node configuration fails, the error now names the reason, and Node-RED logs it as a warning. Until now the editor only said "Something went wrong", and an unexpected error reached it as an empty `{}` ([#458](https://github.com/Foddy/node-red-contrib-huemagic/issues/458)) (thx @JGoor)
11
+ * A bridge that rejects the application key is now reported as such instead of as a bridge that is "currently not able to answer"
12
+ * A request through an HTTPS proxy to an IP address no longer fails on Node.js 26, which refuses an IP address as TLS server name
13
+
14
+ **Under the hood**
15
+
16
+ * The color name under `msg.payload.color` is worked out by HueMagic itself instead of by `color-namer`, which dragged `chroma-js` and the `es5-ext` family with its install script behind it. The names stay exactly the same
17
+ * All remaining dependencies are at their current releases
18
+ * HueMagic installs 9 instead of 21 packages and needs no install scripts, so npm 12 — which blocks the install scripts of dependencies — installs it without warnings. `npm audit` reports no vulnerabilities
19
+
20
+ ### v5.2.0
6
21
 
7
22
  * The "Hue Buttons" node's additional outputs can now also listen to the dial of a Hue Tap Dial Switch: choose "Rotation" instead of a button and set the range of degrees a turn has to fall into, with counterclockwise turns counting as negative ([#457](https://github.com/Foddy/node-red-contrib-huemagic/pull/457)) (thx @FredBlo)
8
23
 
package/README.md CHANGED
@@ -1219,7 +1219,22 @@ If the status of the node has changed via a certain command, the entire command
1219
1219
 
1220
1220
  # Changelog
1221
1221
 
1222
- ### v5.2.0 (latest)
1222
+ ### v5.2.1 (latest)
1223
+
1224
+ **Fixes**
1225
+
1226
+ * The scene search of the "Hue Scene" node says "Searching scenes…" again instead of showing the raw text `hue-rules.config.searching` ([#458](https://github.com/Foddy/node-red-contrib-huemagic/issues/458)) (thx @JGoor)
1227
+ * When a search for lights, groups, scenes, sensors, rules or automations in the node configuration fails, the error now names the reason, and Node-RED logs it as a warning. Until now the editor only said "Something went wrong", and an unexpected error reached it as an empty `{}` ([#458](https://github.com/Foddy/node-red-contrib-huemagic/issues/458)) (thx @JGoor)
1228
+ * A bridge that rejects the application key is now reported as such instead of as a bridge that is "currently not able to answer"
1229
+ * A request through an HTTPS proxy to an IP address no longer fails on Node.js 26, which refuses an IP address as TLS server name
1230
+
1231
+ **Under the hood**
1232
+
1233
+ * The color name under `msg.payload.color` is worked out by HueMagic itself instead of by `color-namer`, which dragged `chroma-js` and the `es5-ext` family with its install script behind it. The names stay exactly the same
1234
+ * All remaining dependencies are at their current releases
1235
+ * HueMagic installs 9 instead of 21 packages and needs no install scripts, so npm 12 — which blocks the install scripts of dependencies — installs it without warnings. `npm audit` reports no vulnerabilities
1236
+
1237
+ ### v5.2.0
1223
1238
 
1224
1239
  * The "Hue Buttons" node's additional outputs can now also listen to the dial of a Hue Tap Dial Switch: choose "Rotation" instead of a button and set the range of degrees a turn has to fall into, with counterclockwise turns counting as negative ([#457](https://github.com/Foddy/node-red-contrib-huemagic/pull/457)) (thx @FredBlo)
1225
1240
 
@@ -158,10 +158,10 @@
158
158
  // CLOSE SEARCH NOTIFICATION
159
159
  notification.close();
160
160
  })
161
- .fail(function()
161
+ .fail(function(xhr)
162
162
  {
163
163
  notification.close();
164
- RED.notify(scope._("hue-automation.config.unknown-error"), "error");
164
+ RED.notify(scope._("hue-automation.config.unknown-error") + (xhr.responseText ? "<br>" + $("<div>").text(xhr.responseText).html() : ""), "error");
165
165
  });
166
166
  }
167
167
 
@@ -994,7 +994,10 @@ module.exports = function(RED)
994
994
  res.end(JSON.stringify(targetRules));
995
995
  })
996
996
  .catch(function(error) {
997
- res.status(500).send(JSON.stringify(error));
997
+ // A PLAIN ERROR WOULD BE SENT AS "{}", SO GIVE BACK ITS MESSAGE
998
+ const message = error.message ? error.message : JSON.stringify(error);
999
+ RED.log.warn("HueMagic: Could not fetch the " + targetType + " resources of the bridge (" + message + ")");
1000
+ res.status(500).send(message);
998
1001
  });
999
1002
  }
1000
1003
  // GET ALL OTHER RESOURCES
@@ -1071,7 +1074,10 @@ module.exports = function(RED)
1071
1074
  res.end(JSON.stringify(targetDevices));
1072
1075
  })
1073
1076
  .catch(function(error) {
1074
- res.status(500).send(JSON.stringify(error));
1077
+ // A PLAIN ERROR WOULD BE SENT AS "{}", SO GIVE BACK ITS MESSAGE
1078
+ const message = error.message ? error.message : JSON.stringify(error);
1079
+ RED.log.warn("HueMagic: Could not fetch the " + targetType + " resources of the bridge (" + message + ")");
1080
+ res.status(500).send(message);
1075
1081
  });
1076
1082
  }
1077
1083
  });
@@ -163,10 +163,10 @@
163
163
  // CLOSE SEARCH NOTIFICATION
164
164
  notification.close();
165
165
  })
166
- .fail(function()
166
+ .fail(function(xhr)
167
167
  {
168
168
  notification.close();
169
- RED.notify(scope._("hue-brightness.config.unknown-error"), "error");
169
+ RED.notify(scope._("hue-brightness.config.unknown-error") + (xhr.responseText ? "<br>" + $("<div>").text(xhr.responseText).html() : ""), "error");
170
170
  });
171
171
  }
172
172
 
@@ -196,10 +196,10 @@
196
196
  // CLOSE SEARCH NOTIFICATION
197
197
  notification.close();
198
198
  })
199
- .fail(function()
199
+ .fail(function(xhr)
200
200
  {
201
201
  notification.close();
202
- RED.notify(scope._("hue-buttons.config.unknown-error"), "error");
202
+ RED.notify(scope._("hue-buttons.config.unknown-error") + (xhr.responseText ? "<br>" + $("<div>").text(xhr.responseText).html() : ""), "error");
203
203
  });
204
204
  }
205
205
 
@@ -158,10 +158,10 @@
158
158
  // CLOSE SEARCH NOTIFICATION
159
159
  notification.close();
160
160
  })
161
- .fail(function()
161
+ .fail(function(xhr)
162
162
  {
163
163
  notification.close();
164
- RED.notify(scope._("hue-contact.config.unknown-error"), "error");
164
+ RED.notify(scope._("hue-contact.config.unknown-error") + (xhr.responseText ? "<br>" + $("<div>").text(xhr.responseText).html() : ""), "error");
165
165
  });
166
166
  }
167
167
 
@@ -169,10 +169,10 @@
169
169
  // CLOSE SEARCH NOTIFICATION
170
170
  notification.close();
171
171
  })
172
- .fail(function()
172
+ .fail(function(xhr)
173
173
  {
174
174
  notification.close();
175
- RED.notify(scope._("hue-group.config.unknown-error"), "error");
175
+ RED.notify(scope._("hue-group.config.unknown-error") + (xhr.responseText ? "<br>" + $("<div>").text(xhr.responseText).html() : ""), "error");
176
176
  });
177
177
  }
178
178
 
@@ -165,10 +165,10 @@
165
165
  // CLOSE SEARCH NOTIFICATION
166
166
  notification.close();
167
167
  })
168
- .fail(function()
168
+ .fail(function(xhr)
169
169
  {
170
170
  notification.close();
171
- RED.notify(scope._("hue-light.config.unknown-error"), "error");
171
+ RED.notify(scope._("hue-light.config.unknown-error") + (xhr.responseText ? "<br>" + $("<div>").text(xhr.responseText).html() : ""), "error");
172
172
  });
173
173
  }
174
174
 
@@ -158,10 +158,10 @@
158
158
  // CLOSE SEARCH NOTIFICATION
159
159
  notification.close();
160
160
  })
161
- .fail(function()
161
+ .fail(function(xhr)
162
162
  {
163
163
  notification.close();
164
- RED.notify(scope._("hue-motion.config.unknown-error"), "error");
164
+ RED.notify(scope._("hue-motion.config.unknown-error") + (xhr.responseText ? "<br>" + $("<div>").text(xhr.responseText).html() : ""), "error");
165
165
  });
166
166
  }
167
167
 
@@ -151,10 +151,10 @@
151
151
  // CLOSE SEARCH NOTIFICATION
152
152
  notification.close();
153
153
  })
154
- .fail(function()
154
+ .fail(function(xhr)
155
155
  {
156
156
  notification.close();
157
- RED.notify(scope._("hue-rules.config.unknown-error"), "error");
157
+ RED.notify(scope._("hue-rules.config.unknown-error") + (xhr.responseText ? "<br>" + $("<div>").text(xhr.responseText).html() : ""), "error");
158
158
  });
159
159
  }
160
160
 
@@ -91,7 +91,7 @@
91
91
  var current = $('#node-input-sceneid').val();
92
92
 
93
93
  // TRIGGER SEARCHING NOTIFICATION
94
- var notification = RED.notify(scope._("hue-rules.config.searching"), { type: "compact", modal: true, fixed: true });
94
+ var notification = RED.notify(scope._("hue-scene.config.searching"), { type: "compact", modal: true, fixed: true });
95
95
 
96
96
  // GET THE SCENES
97
97
  $.get('hue/resources', { bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "scene" })
@@ -134,10 +134,10 @@
134
134
  // CLOSE SEARCH NOTIFICATION
135
135
  notification.close();
136
136
  })
137
- .fail(function()
137
+ .fail(function(xhr)
138
138
  {
139
139
  notification.close();
140
- RED.notify(scope._("hue-scene.config.unknown-error"), "error");
140
+ RED.notify(scope._("hue-scene.config.unknown-error") + (xhr.responseText ? "<br>" + $("<div>").text(xhr.responseText).html() : ""), "error");
141
141
  });
142
142
  }
143
143
 
@@ -158,10 +158,10 @@
158
158
  // CLOSE SEARCH NOTIFICATION
159
159
  notification.close();
160
160
  })
161
- .fail(function()
161
+ .fail(function(xhr)
162
162
  {
163
163
  notification.close();
164
- RED.notify(scope._("hue-speaker.config.unknown-error"), "error");
164
+ RED.notify(scope._("hue-speaker.config.unknown-error") + (xhr.responseText ? "<br>" + $("<div>").text(xhr.responseText).html() : ""), "error");
165
165
  });
166
166
  }
167
167
 
@@ -163,10 +163,10 @@
163
163
  // CLOSE SEARCH NOTIFICATION
164
164
  notification.close();
165
165
  })
166
- .fail(function()
166
+ .fail(function(xhr)
167
167
  {
168
168
  notification.close();
169
- RED.notify(scope._("hue-temperature.config.unknown-error"), "error");
169
+ RED.notify(scope._("hue-temperature.config.unknown-error") + (xhr.responseText ? "<br>" + $("<div>").text(xhr.responseText).html() : ""), "error");
170
170
  });
171
171
  }
172
172
 
@@ -111,8 +111,9 @@ function API()
111
111
  {
112
112
  let errors = error.response.data;
113
113
 
114
- // AN OVERLOADED BRIDGE ANSWERS WITH A HTML ERROR PAGE
115
- if(typeof errors === 'string') { errors = "The bridge is currently not able to answer (HTTP " + error.response.status + ")."; }
114
+ // AN OVERLOADED BRIDGE ANSWERS WITH A HTML ERROR PAGE, AND SO DOES ONE THAT REJECTS THE KEY
115
+ if(typeof errors === 'string' && (error.response.status === 401 || error.response.status === 403)) { errors = "The bridge does not accept the application key (HTTP " + error.response.status + ")."; }
116
+ else if(typeof errors === 'string') { errors = "The bridge is currently not able to answer (HTTP " + error.response.status + ")."; }
116
117
  else if(errors && errors.errors) { errors = errors.errors; }
117
118
 
118
119
  reject({ status: error.response.status, errors: errors });
@@ -1,6 +1,5 @@
1
1
  // EXTERNAL HELPERS
2
2
  const colornames = require("colornames");
3
- const colornamer = require('color-namer');
4
3
 
5
4
  // THE DOMINANT COLORS OF AN IMAGE, LOADED ON DEMAND
6
5
  function getColors(...args)
@@ -290,6 +289,49 @@ function hexRgb(hex, options = {})
290
289
  return [red, green, blue];
291
290
  }
292
291
 
292
+ // THE BASIC COLORS A LIGHT IS NAMED AFTER (THE "BASIC" LIST OF color-namer, MIT)
293
+ const basicColors = [
294
+ ["black", "000000"], ["blue", "0000FF"], ["cyan", "00FFFF"], ["green", "008000"], ["teal", "008080"],
295
+ ["turquoise", "40E0D0"], ["indigo", "4B0082"], ["gray", "808080"], ["purple", "800080"], ["brown", "A52A2A"],
296
+ ["tan", "D2B48C"], ["violet", "EE82EE"], ["beige", "F5F5DC"], ["fuchsia", "FF00FF"], ["gold", "FFD700"],
297
+ ["magenta", "FF00FF"], ["orange", "FFA500"], ["pink", "FFC0CB"], ["red", "FF0000"], ["white", "FFFFFF"],
298
+ ["yellow", "FFFF00"]
299
+ ].map(function([name, hex]) { return { name: name, lab: hexLab(hex) }; });
300
+
301
+ // HEX -> CIE LAB (D65), THE SAME WAY chroma-js DOES IT
302
+ function hexLab(hex)
303
+ {
304
+ const linear = hexRgb(hex).slice(0, 3).map(function(value)
305
+ {
306
+ value = value / 255;
307
+ return (value <= 0.04045) ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
308
+ });
309
+ const [r, g, b] = linear;
310
+ const lab = function(t) { return (t > 0.008856452) ? Math.pow(t, 1 / 3) : t / 0.12841855 + 0.137931034; };
311
+
312
+ const x = lab((0.4124564 * r + 0.3575761 * g + 0.1804375 * b) / 0.950470);
313
+ const y = lab(0.2126729 * r + 0.7151522 * g + 0.0721750 * b);
314
+ const z = lab((0.0193339 * r + 0.1191920 * g + 0.9503041 * b) / 1.088830);
315
+
316
+ return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
317
+ }
318
+
319
+ // HEX -> NAME OF THE NEAREST BASIC COLOR
320
+ function colorName(hex)
321
+ {
322
+ const target = hexLab(hex);
323
+ let nearest = false;
324
+ let nearestDistance = Infinity;
325
+
326
+ for (const one of basicColors)
327
+ {
328
+ const distance = Math.hypot(target[0] - one.lab[0], target[1] - one.lab[1], target[2] - one.lab[2]);
329
+ if(distance < nearestDistance) { nearest = one.name; nearestDistance = distance; }
330
+ }
331
+
332
+ return nearest;
333
+ }
334
+
293
335
  // RANDOM HEX COLOR GENERATOR
294
336
  function randomHexColor()
295
337
  {
@@ -394,7 +436,7 @@ module.exports.xyBriToRgb = xyBriToRgb;
394
436
  module.exports.hexRgb = hexRgb;
395
437
  module.exports.randomHexColor = randomHexColor;
396
438
  module.exports.colornames = colornames;
397
- module.exports.colornamer = colornamer;
439
+ module.exports.colorName = colorName;
398
440
  module.exports.getColors = getColors;
399
441
  module.exports.colorTemperature = colorTemperature;
400
442
  module.exports.mixColors = mixColors;
@@ -1,6 +1,7 @@
1
1
  const http = require('http');
2
2
  const https = require('https');
3
3
  const tls = require('tls');
4
+ const net = require('net');
4
5
 
5
6
  // NOTHING WE TALK TO ANSWERS WITH MORE THAN THIS, AND A RUNAWAY RESPONSE MUST NOT EAT THE HEAP
6
7
  const MAX_BYTES = 16 * 1024 * 1024;
@@ -139,7 +140,8 @@ async function send({ url, method = 'GET', headers = {}, data = null, timeout =
139
140
  delete options.agent;
140
141
  options.createConnection = function()
141
142
  {
142
- return tls.connect({ socket: tunnelSocket, servername: target.hostname, rejectUnauthorized: rejectUnauthorized });
143
+ // SNI TAKES NO IP ADDRESS, NODE 26 EVEN THROWS ON ONE
144
+ return tls.connect({ socket: tunnelSocket, servername: net.isIP(target.hostname) ? undefined : target.hostname, rejectUnauthorized: rejectUnauthorized });
143
145
  };
144
146
  }
145
147
  else
@@ -384,8 +384,7 @@ class HueGroupMessage
384
384
 
385
385
  if(options.colornames == true)
386
386
  {
387
- var cNamesArray = colorUtils.colornamer(colorUtils.rgbHex(RGB.r, RGB.g, RGB.b));
388
- this.message.payload.color = cNamesArray.basic[0]["name"];
387
+ this.message.payload.color = colorUtils.colorName(colorUtils.rgbHex(RGB.r, RGB.g, RGB.b));
389
388
  }
390
389
  }
391
390
 
@@ -445,8 +444,7 @@ class HueLightMessage
445
444
 
446
445
  if(options.colornames == true)
447
446
  {
448
- var cNamesArray = colorUtils.colornamer(colorUtils.rgbHex(RGB.r, RGB.g, RGB.b));
449
- this.message.payload.color = cNamesArray.basic[0]["name"];
447
+ this.message.payload.color = colorUtils.colorName(colorUtils.rgbHex(RGB.r, RGB.g, RGB.b));
450
448
  }
451
449
 
452
450
  this.message.info.model.colorGamut = lightService.color.gamut;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-huemagic",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "description": "Philips Hue nodes to control bridges, lights, groups, scenes, rules, automations, buttons, switches, dials, doorbells, speakers, motion sensors, cameras, contact sensors, temperature sensors, light level sensors and the Hue Play HDMI Sync Box using Node-RED.",
5
5
  "author": "foddy",
6
6
  "homepage": "https://github.com/Foddy/node-red-contrib-huemagic",
@@ -58,7 +58,6 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "async": "^3.2.6",
61
- "color-namer": "^1.4.0",
62
61
  "colornames": "^1.1.1",
63
62
  "dayjs": "^1.11.23",
64
63
  "deep-object-diff": "^1.1.9",