node-red-contrib-huemagic 4.1.0 → 4.2.2
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 +77 -2
- package/README.md +20 -13
- package/huemagic/hue-bridge-config.html +2 -2
- package/huemagic/hue-bridge-config.js +133 -71
- package/huemagic/hue-brightness.js +26 -4
- package/huemagic/hue-buttons.js +1 -1
- package/huemagic/hue-group.js +149 -56
- package/huemagic/hue-light.js +192 -72
- package/huemagic/hue-magic.html +0 -2
- package/huemagic/hue-motion.js +27 -5
- package/huemagic/hue-rules.js +26 -7
- package/huemagic/hue-scene.js +62 -16
- package/huemagic/hue-temperature.js +26 -4
- package/huemagic/locales/de/hue-bridge-config.html +1 -1
- package/huemagic/utils/api.js +11 -17
- package/huemagic/utils/messages.js +52 -50
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,83 @@
|
|
|
1
|
-
[](https://flows.nodered.org/node/node-red-contrib-huemagic)
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### v4.2.2 (latest)
|
|
6
|
+
|
|
7
|
+
* HueMagic can now be installed again on older Node-RED versions without official support
|
|
8
|
+
* Fixed an issue for Hue Group nodes not getting/updating their current status ([#342](https://github.com/Foddy/node-red-contrib-huemagic/issues/342)) (thx @bmdevx)
|
|
9
|
+
* Fixed an error with non-functioning node configurations
|
|
10
|
+
|
|
11
|
+
### v4.2.1
|
|
12
|
+
|
|
13
|
+
* Commands are now re-executed up to three times if they fail due to a bridge timeout
|
|
14
|
+
* The "image" option on the "Hue Light" node will now set the corresponding gradient colors on supported resources
|
|
15
|
+
* Better handling of broken connections to the bridge ([#309](https://github.com/Foddy/node-red-contrib-huemagic/pull/309)) (thx)
|
|
16
|
+
* Fixed an error with the "Hue Scenes" node on newer bridge firmwares ([#335](https://github.com/Foddy/node-red-contrib-huemagic/issues/335)) ([#339](https://github.com/Foddy/node-red-contrib-huemagic/pull/339)) (thx)
|
|
17
|
+
* Fixed an uncaught exception on newer bridge firmwares ([#302](https://github.com/Foddy/node-red-contrib-huemagic/issues/302)) ([#309](https://github.com/Foddy/node-red-contrib-huemagic/pull/309)) (thx)
|
|
18
|
+
* Updated dependencies to the latest versions
|
|
19
|
+
* Fixed some typos here and there
|
|
20
|
+
|
|
21
|
+
### v4.1.0
|
|
22
|
+
|
|
23
|
+
* New queue worker throttles the number of parallel requests to the bridge to avoid 503 API limit errors (can be configured in the Bridge configuration)
|
|
24
|
+
* Resources are now alphabetically sorted in the node´s configuration interface ([#282](https://github.com/Foddy/node-red-contrib-huemagic/pull/282)) (thx)
|
|
25
|
+
* "Hue Brightness" node was optimized to output more accurate "dark" and "dayLight" values
|
|
26
|
+
* Several optimizations in the documentation of some nodes
|
|
27
|
+
|
|
28
|
+
### v4.0.5
|
|
29
|
+
|
|
30
|
+
* The "Hue Group" node now contains the "resources" information with all linked resources behind the group/zone
|
|
31
|
+
* Fixed an issue that caused Node-RED to restart if a command was sent before a node was initialized
|
|
32
|
+
|
|
33
|
+
### v4.0.4
|
|
34
|
+
|
|
35
|
+
* Fixed an issue with the bridge config node checking for updates too frequently ([#246](https://github.com/Foddy/node-red-contrib-huemagic/issues/246#issuecomment-1009376442))
|
|
36
|
+
* Fixed an issue with multiple bridges configured
|
|
37
|
+
|
|
38
|
+
### v4.0.3
|
|
39
|
+
|
|
40
|
+
> **Attention!** HueMagic v4+ has been almost completely rewritten under the hood and requires at least the (square-shaped) Philips Hue Bridge firmware 1948086000+ from November 1st, 2021 ([Upgrade instructions](https://www.lighting.philips.com/content/B2C/en_US/microsites/meethue/marketing-catalog/huewireless_ca/support/security-advisory/general/where-and-how-can-i-update-my-hue-system-with-the-latest-software.html)) and Node-RED v1+ ([Upgrade instructions](https://nodered.org/docs/getting-started/local#upgrading-node-red)). If you are upgrading from a previous HueMagic version to the v4, you will have to reconfigure (not completely rebuild) all nodes by clicking them and selecting the appropriate device from the list. This also applies to nodes / functions that are operated in universal mode, as the numeric identifiers of the latest Philips Hue API version have been replaced in UUIDs. The nodes "Hue Switch", "Hue Button" & "Hue Tap" have been replaced in v4 by the universal and uniform node "Hue Buttons", which works with all button / switch devices that are connected to the Hue Bridge (please note here also the new API in the documentation). The request and return objects of the individual nodes are largely compatible with older HueMagic versions - with the exception of the nodes "Hue Bridge", "Hue Buttons", "Hue Scene" & "Hue Group". These need to be adjusted in the v4. Make sure that you meet the minimum technical requirements and have a quiet minute for the migration before upgrading to the v4.
|
|
41
|
+
|
|
42
|
+
* HueMagic speaks now directly with the bridge without any submodules *(huejay dependency removed)*
|
|
43
|
+
* Migrated to the newest CLIP/v2 API version from the Philips Hue bridge
|
|
44
|
+
* Nodes are now updated via push notifications (SSE) from the bridge instead of periodic polling
|
|
45
|
+
* Instant "current status" queries on each node with no loading time
|
|
46
|
+
* "Hue Buttons" node supports all new Philips Hue buttons/switches (e.g. Dimmer Switch v2, Hue Wall Switch…)
|
|
47
|
+
* All nodes provide additional property information in the output (check docs)
|
|
48
|
+
* New universal node "Hue Buttons" replaces the following nodes: "Hue Switch", "Hue Button", "Hue Tap"
|
|
49
|
+
* New "updated" object for all nodes, which only contains the properties that have been updated since the last state
|
|
50
|
+
* New configuration option to suppress first message after node initialization (for all nodes)
|
|
51
|
+
* New gradient color setting for compatible light sources (in "Hue Light" node)
|
|
52
|
+
* New inject button for almost all nodes, which triggers the current status of a node
|
|
53
|
+
* New "universal mode" support for the "Hue Rule" node
|
|
54
|
+
* New SVG-version of each node icon for higher quality rendering in the Node-RED UI
|
|
55
|
+
* New and full featured examples for each node right inside Node-RED
|
|
56
|
+
* New color mix feature in "Hue Light" nodes with the ability to mix the current light color with another
|
|
57
|
+
* New automatic brightness support based on the current time for "Hue Light" & "Hue Group" nodes
|
|
58
|
+
* New "Superhero", "Neon City" & "Christmas" (for next year, sorry) animations in "Hue Magic" node
|
|
59
|
+
* The custom alert effect on "Hue Light" & "Hue Group" nodes can now also be configured in brightness
|
|
60
|
+
* All nodes will now also forward the last command that has been applied ([#249](https://github.com/Foddy/node-red-contrib-huemagic/issues/249))
|
|
61
|
+
* "Hue Temperature" & "Hue Brightness" nodes can now also be activated & deactivated
|
|
62
|
+
* "Hue Light" & "Hue Group" nodes can now also receive XY color settings
|
|
63
|
+
* "Hue Light" & "Hue Group" can now also receive a named color temperature setting
|
|
64
|
+
* "Hue Light" & "Hue Group" nodes can now receive future brightness states in "turned off" mode ([#244](https://github.com/Foddy/node-red-contrib-huemagic/issues/244))
|
|
65
|
+
* Automatic light temperature setting outputs now values from 153 (coldest) to 500 (warmest)
|
|
66
|
+
* Automatic color correction based on the light´s capabilities for more accurate color settings
|
|
67
|
+
* Optimized node editor configuration UI to better match the current Node-RED´s UI
|
|
68
|
+
* The option for "automatic firmware updates" on the bridge moved to the bridge configuration node
|
|
69
|
+
* "Hue Group" node does no longer contain the "msg.info.model" & "msg.info.class" property
|
|
70
|
+
* Fixed timeout connection issues to the bridge
|
|
71
|
+
* Fixed an issue with non stopping custom animations ([#222](https://github.com/Foddy/node-red-contrib-huemagic/issues/222)), ([#224](https://github.com/Foddy/node-red-contrib-huemagic/issues/224)) & ([#226](https://github.com/Foddy/node-red-contrib-huemagic/pull/226)) (thx)
|
|
72
|
+
* Node-RED will no longer crash if there is no active connection to the bridge ([#237](https://github.com/Foddy/node-red-contrib-huemagic/issues/237))
|
|
73
|
+
* Fixed an issue that prevented the light / group from not reporting its own status when queried & node events were deactivated ([#248](https://github.com/Foddy/node-red-contrib-huemagic/issues/248))
|
|
74
|
+
* Fixed an issue with nodes in universal mode ([#245](https://github.com/Foddy/node-red-contrib-huemagic/issues/245))
|
|
75
|
+
* A possible attack target has been fixed ([#217](https://github.com/Foddy/node-red-contrib-huemagic/issues/217))
|
|
76
|
+
* Moved away from "moment.js" to "Day.js" for date/time formatting inside the nodes
|
|
77
|
+
* Updated README and help section on each node
|
|
78
|
+
* Updated dependencies to the latest version
|
|
79
|
+
|
|
80
|
+
### v3.0.0
|
|
6
81
|
* Hue Motion, Hue Brightness, Hue Tap, Hue Switch & Hue Button nodes can now receive a status request
|
|
7
82
|
* New "Universal Mode" for the Hue Motion, Hue Brightness, Hue Tap, Hue Switch & Hue Button nodes
|
|
8
83
|
* The "colorTemp" property for Hue Light & Hue Group nodes can now also be set to "cold", "normal", "warm" or "auto"
|
package/README.md
CHANGED
|
@@ -796,11 +796,27 @@ If the status of the node has changed via a certain command, the entire command
|
|
|
796
796
|
|
|
797
797
|
# Changelog
|
|
798
798
|
|
|
799
|
-
### v4.
|
|
799
|
+
### v4.2.2 (latest)
|
|
800
|
+
|
|
801
|
+
* HueMagic can now be installed again on older Node-RED versions without official support
|
|
802
|
+
* Fixed an issue for Hue Group nodes not getting/updating their current status ([#342](https://github.com/Foddy/node-red-contrib-huemagic/issues/342)) (thx @bmdevx)
|
|
803
|
+
* Fixed an error with non-functioning node configurations
|
|
804
|
+
|
|
805
|
+
### v4.2.1
|
|
806
|
+
|
|
807
|
+
* Commands are now re-executed up to three times if they fail due to a bridge timeout
|
|
808
|
+
* The "image" option on the "Hue Light" node will now set the corresponding gradient colors on supported resources
|
|
809
|
+
* Better handling of broken connections to the bridge ([#309](https://github.com/Foddy/node-red-contrib-huemagic/pull/309)) (thx)
|
|
810
|
+
* Fixed an error with the "Hue Scenes" node on newer bridge firmwares ([#335](https://github.com/Foddy/node-red-contrib-huemagic/issues/335)) ([#339](https://github.com/Foddy/node-red-contrib-huemagic/pull/339)) (thx)
|
|
811
|
+
* Fixed an uncaught exception on newer bridge firmwares ([#302](https://github.com/Foddy/node-red-contrib-huemagic/issues/302)) ([#309](https://github.com/Foddy/node-red-contrib-huemagic/pull/309)) (thx)
|
|
812
|
+
* Updated dependencies to the latest versions
|
|
813
|
+
* Fixed some typos here and there
|
|
814
|
+
|
|
815
|
+
### v4.1.0
|
|
800
816
|
|
|
801
817
|
* New queue worker throttles the number of parallel requests to the bridge to avoid 503 API limit errors (can be configured in the Bridge configuration)
|
|
802
|
-
* Resources are now alphabetically sorted in the node´s configuration
|
|
803
|
-
* "Hue
|
|
818
|
+
* Resources are now alphabetically sorted in the node´s configuration interface ([#282](https://github.com/Foddy/node-red-contrib-huemagic/pull/282)) (thx)
|
|
819
|
+
* "Hue Brightness" node was optimized to output more accurate "dark" and "dayLight" values
|
|
804
820
|
* Several optimizations in the documentation of some nodes
|
|
805
821
|
|
|
806
822
|
### v4.0.5
|
|
@@ -868,17 +884,8 @@ If the status of the node has changed via a certain command, the entire command
|
|
|
868
884
|
* Fixed an error with future states and the HTTP request node ([#200](https://github.com/Foddy/node-red-contrib-huemagic/pull/200))
|
|
869
885
|
* Other optimizations, dependency updates and clean up
|
|
870
886
|
|
|
871
|
-
### v2.8.6
|
|
872
|
-
* Optimized random color mode for Hue Magic, Hue Light & Hue Group nodes ([#190](https://github.com/Foddy/node-red-contrib-huemagic/pull/190))
|
|
873
|
-
* New Hue Button node ([#191](https://github.com/Foddy/node-red-contrib-huemagic/pull/191))
|
|
874
|
-
* Updated README and Hue Button node docs (+ localized in German)
|
|
875
|
-
|
|
876
|
-
### v2.8.2
|
|
877
|
-
* Fixed an issue with Hue Light & Hue Group nodes on extended mode ([#179](https://github.com/Foddy/node-red-contrib-huemagic/issues/179))
|
|
878
|
-
* Dependency updates
|
|
879
|
-
|
|
880
887
|
### Previous versions
|
|
881
|
-
|
|
888
|
+
The full changelog [changelog](https://github.com/Foddy/node-red-contrib-huemagic/blob/master/CHANGELOG.md) can be viewed here…
|
|
882
889
|
|
|
883
890
|
|
|
884
891
|
***
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
name: { value:"Hue Bridge", required: true },
|
|
52
52
|
bridge: { value:"", required: true },
|
|
53
53
|
key: { value:"", required: true },
|
|
54
|
-
worker: { value: 10, required: true, validate:function(v) {
|
|
55
|
-
return (!isNaN(v) && v > 0)
|
|
54
|
+
worker: { value: 10, required: true, validate: function(v) {
|
|
55
|
+
return (!isNaN(v) && v > 0);
|
|
56
56
|
}},
|
|
57
57
|
autoupdates: { value: true },
|
|
58
58
|
disableupdates: { value: false }
|
|
@@ -34,9 +34,10 @@ module.exports = function(RED)
|
|
|
34
34
|
this.lastStates = {};
|
|
35
35
|
this.events = new events.EventEmitter();
|
|
36
36
|
this.patchQueue = null;
|
|
37
|
+
this.timerWatchDog = null;
|
|
37
38
|
|
|
38
39
|
// RESOURCE ID PATTERN
|
|
39
|
-
this.validResourceID =
|
|
40
|
+
this.validResourceID = /[a-zA-Z0-9]/gi;
|
|
40
41
|
|
|
41
42
|
// FIRMWARE UPDATE TIMEOUT
|
|
42
43
|
this.firmwareUpdateTimeout = null;
|
|
@@ -44,6 +45,31 @@ module.exports = function(RED)
|
|
|
44
45
|
// CREATE NODE
|
|
45
46
|
RED.nodes.createNode(scope, config);
|
|
46
47
|
|
|
48
|
+
// PERIODICALLY CHECK WETHER BRIDGE IS CONNECTED
|
|
49
|
+
this.startWatchdog = function()
|
|
50
|
+
{
|
|
51
|
+
if (this.timerWatchDog !== null) clearTimeout(this.timerWatchDog);
|
|
52
|
+
this.timerWatchDog = setTimeout(function()
|
|
53
|
+
{
|
|
54
|
+
try
|
|
55
|
+
{
|
|
56
|
+
API.request({ config: config, resource: "/config", version: 1 })
|
|
57
|
+
.then(function(bridgeInformation)
|
|
58
|
+
{
|
|
59
|
+
scope.startWatchdog();
|
|
60
|
+
})
|
|
61
|
+
.catch(function(error)
|
|
62
|
+
{
|
|
63
|
+
scope.log("Error requesting info from the bridge. Reconnect in some secs. " + error.message);
|
|
64
|
+
scope.start();
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
scope.log("Lost connection with the bridge. Reconnect in some secs. " + error.message);
|
|
68
|
+
scope.start();
|
|
69
|
+
}
|
|
70
|
+
}, 10000);
|
|
71
|
+
}
|
|
72
|
+
|
|
47
73
|
// INITIALIZE
|
|
48
74
|
this.start = function()
|
|
49
75
|
{
|
|
@@ -74,6 +100,9 @@ module.exports = function(RED)
|
|
|
74
100
|
|
|
75
101
|
// START LOOKING FOR FIRMWARE-UPDATES
|
|
76
102
|
scope.autoUpdateFirmware();
|
|
103
|
+
|
|
104
|
+
// START WATCHDOG
|
|
105
|
+
scope.startWatchdog();
|
|
77
106
|
return true;
|
|
78
107
|
})
|
|
79
108
|
.catch(function(error)
|
|
@@ -303,96 +332,129 @@ module.exports = function(RED)
|
|
|
303
332
|
|
|
304
333
|
if(type == "bridge")
|
|
305
334
|
{
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
335
|
+
try {
|
|
336
|
+
const message = new HueBridgeMessage(targetResource, options);
|
|
337
|
+
|
|
338
|
+
// GET CURRENT STATE MESSAGE
|
|
339
|
+
let currentState = message.msg;
|
|
340
|
+
return currentState;
|
|
341
|
+
} catch (error) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
|
|
311
345
|
}
|
|
312
346
|
else if(type == "light")
|
|
313
347
|
{
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
348
|
+
try {
|
|
349
|
+
const message = new HueLightMessage(targetResource, options);
|
|
350
|
+
|
|
351
|
+
// GET & SAVE LAST STATE AND DIFFERENCES
|
|
352
|
+
let currentState = message.msg;
|
|
353
|
+
scope.lastStates[type+targetResource.id] = Object.assign({}, currentState);
|
|
354
|
+
currentState.updated = (lastState === false) ? {} : diff(lastState, currentState);
|
|
355
|
+
currentState.lastState = lastState;
|
|
356
|
+
|
|
357
|
+
return currentState;
|
|
358
|
+
} catch (error) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
323
361
|
}
|
|
324
362
|
else if(type == "group")
|
|
325
363
|
{
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
364
|
+
try {
|
|
365
|
+
// GET MESSAGE
|
|
366
|
+
const message = new HueGroupMessage(targetResource, { resources: scope.resources, ...options});
|
|
367
|
+
|
|
368
|
+
// GET & SAVE LAST STATE AND DIFFERENCES
|
|
369
|
+
let currentState = message.msg;
|
|
370
|
+
scope.lastStates[type+targetResource.id] = Object.assign({}, currentState);
|
|
371
|
+
currentState.updated = (lastState === false) ? {} : diff(lastState, currentState);
|
|
372
|
+
currentState.lastState = lastState;
|
|
373
|
+
|
|
374
|
+
return currentState;
|
|
375
|
+
} catch (error) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
336
378
|
}
|
|
337
379
|
else if(type == "button")
|
|
338
380
|
{
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
381
|
+
try {
|
|
382
|
+
const message = new HueButtonsMessage(targetResource, options);
|
|
383
|
+
|
|
384
|
+
// GET & SAVE LAST STATE AND DIFFERENCES
|
|
385
|
+
let currentState = message.msg;
|
|
386
|
+
scope.lastStates[type+targetResource.id] = Object.assign({}, currentState);
|
|
387
|
+
currentState.updated = (lastState === false) ? {} : diff(lastState, currentState);
|
|
388
|
+
currentState.lastState = lastState;
|
|
389
|
+
|
|
390
|
+
return currentState;
|
|
391
|
+
} catch (error) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
348
394
|
}
|
|
349
395
|
else if(type == "motion")
|
|
350
396
|
{
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
397
|
+
try {
|
|
398
|
+
const message = new HueMotionMessage(targetResource, options);
|
|
399
|
+
|
|
400
|
+
// GET & SAVE LAST STATE AND DIFFERENCES
|
|
401
|
+
let currentState = message.msg;
|
|
402
|
+
scope.lastStates[type+targetResource.id] = Object.assign({}, currentState);
|
|
403
|
+
currentState.updated = (lastState === false) ? {} : diff(lastState, currentState);
|
|
404
|
+
currentState.lastState = lastState;
|
|
405
|
+
|
|
406
|
+
return currentState;
|
|
407
|
+
} catch (error) {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
360
410
|
}
|
|
361
411
|
else if(type == "temperature")
|
|
362
412
|
{
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
413
|
+
try {
|
|
414
|
+
const message = new HueTemperatureMessage(targetResource, options);
|
|
415
|
+
|
|
416
|
+
// GET & SAVE LAST STATE AND DIFFERENCES
|
|
417
|
+
let currentState = message.msg;
|
|
418
|
+
scope.lastStates[type+targetResource.id] = Object.assign({}, currentState);
|
|
419
|
+
currentState.updated = (lastState === false) ? {} : diff(lastState, currentState);
|
|
420
|
+
currentState.lastState = lastState;
|
|
421
|
+
|
|
422
|
+
return currentState;
|
|
423
|
+
} catch (error) {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
372
426
|
}
|
|
373
427
|
else if(type == "light_level")
|
|
374
428
|
{
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
429
|
+
try {
|
|
430
|
+
const message = new HueBrightnessMessage(targetResource, options);
|
|
431
|
+
|
|
432
|
+
// GET & SAVE LAST STATE AND DIFFERENCES
|
|
433
|
+
let currentState = message.msg;
|
|
434
|
+
scope.lastStates[type+targetResource.id] = Object.assign({}, currentState);
|
|
435
|
+
currentState.updated = (lastState === false) ? {} : diff(lastState, currentState);
|
|
436
|
+
currentState.lastState = lastState;
|
|
437
|
+
|
|
438
|
+
return currentState;
|
|
439
|
+
} catch (error) {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
384
442
|
}
|
|
385
443
|
else if(type == "rule")
|
|
386
444
|
{
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
445
|
+
try {
|
|
446
|
+
const message = new HueRulesMessage(targetResource, options);
|
|
447
|
+
|
|
448
|
+
// GET & SAVE LAST STATE AND DIFFERENCES
|
|
449
|
+
let currentState = message.msg;
|
|
450
|
+
scope.lastStates[type+targetResource.id] = Object.assign({}, currentState);
|
|
451
|
+
currentState.updated = (lastState === false) ? {} : diff(lastState, currentState);
|
|
452
|
+
currentState.lastState = lastState;
|
|
453
|
+
|
|
454
|
+
return currentState;
|
|
455
|
+
} catch (error) {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
396
458
|
}
|
|
397
459
|
else
|
|
398
460
|
{
|
|
@@ -598,7 +660,7 @@ module.exports = function(RED)
|
|
|
598
660
|
//
|
|
599
661
|
// START THE MAGIC
|
|
600
662
|
this.start();
|
|
601
|
-
|
|
663
|
+
|
|
602
664
|
//
|
|
603
665
|
// CLOSE NODE / REMOVE EVENT LISTENER
|
|
604
666
|
this.on('close', function()
|
|
@@ -8,6 +8,7 @@ module.exports = function(RED)
|
|
|
8
8
|
|
|
9
9
|
const scope = this;
|
|
10
10
|
const bridge = RED.nodes.getNode(config.bridge);
|
|
11
|
+
const async = require('async');
|
|
11
12
|
|
|
12
13
|
// SAVE LAST COMMAND
|
|
13
14
|
this.lastCommand = null;
|
|
@@ -116,7 +117,7 @@ module.exports = function(RED)
|
|
|
116
117
|
let currentState = bridge.get("light_level", tempSensorID);
|
|
117
118
|
if(!currentState)
|
|
118
119
|
{
|
|
119
|
-
scope.error("The sensor in not yet available. Please wait until HueMagic has established a connection with the bridge or check whether the resource ID in the configuration is valid
|
|
120
|
+
scope.error("The sensor in not yet available. Please wait until HueMagic has established a connection with the bridge or check whether the resource ID in the configuration is valid.");
|
|
120
121
|
return false;
|
|
121
122
|
}
|
|
122
123
|
|
|
@@ -157,9 +158,30 @@ module.exports = function(RED)
|
|
|
157
158
|
}
|
|
158
159
|
|
|
159
160
|
// PATCH!
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
async.retry({
|
|
162
|
+
times: 3,
|
|
163
|
+
errorFilter: function(err) {
|
|
164
|
+
return (err.status == 503);
|
|
165
|
+
},
|
|
166
|
+
interval: function(retryCount) { return retryCount*2000; }
|
|
167
|
+
},
|
|
168
|
+
function(callback, results)
|
|
169
|
+
{
|
|
170
|
+
bridge.patch("light_level", tempSensorID, patchObject)
|
|
171
|
+
.then(function() { callback(null, true); })
|
|
172
|
+
.catch(function(errors) { callback(errors, null); });
|
|
173
|
+
},
|
|
174
|
+
function(errors, success)
|
|
175
|
+
{
|
|
176
|
+
if(errors)
|
|
177
|
+
{
|
|
178
|
+
scope.error(errors);
|
|
179
|
+
}
|
|
180
|
+
else if(done)
|
|
181
|
+
{
|
|
182
|
+
done();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
163
185
|
}
|
|
164
186
|
else
|
|
165
187
|
{
|
package/huemagic/hue-buttons.js
CHANGED
|
@@ -134,7 +134,7 @@ module.exports = function(RED)
|
|
|
134
134
|
let currentState = bridge.get("button", tempSensorID);
|
|
135
135
|
if(!currentState)
|
|
136
136
|
{
|
|
137
|
-
scope.error("The button/switch in not yet available. Please wait until HueMagic has established a connection with the bridge or check whether the resource ID in the configuration is valid
|
|
137
|
+
scope.error("The button/switch in not yet available. Please wait until HueMagic has established a connection with the bridge or check whether the resource ID in the configuration is valid.");
|
|
138
138
|
return false;
|
|
139
139
|
}
|
|
140
140
|
|