Skip to content

Commit

Permalink
Merge pull request #409 from FredBlo/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Foddy committed Nov 5, 2022
2 parents 1af6c29 + 66da2cf commit f72d311
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 58 deletions.
28 changes: 20 additions & 8 deletions huemagic/hue-bridge-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,23 @@ module.exports = function(RED)
})
.catch(function(error)
{
scope.log("Error requesting info from the bridge. Reconnect in some secs. " + error.message);
scope.start();
});
// scope.log("Error requesting info from the bridge. Reconnect in some secs. " + error.message);
// debug
if (error.status !== 429) {
scope.log("Error requesting info from the bridge. Reconnect in some secs. " + ((typeof(error.message) == 'undefined') ? JSON.stringify(error) : error.message));
// end debug
scope.start();
} else {
// Bridge did not respond because it is currently overloaded (=error 429), but it is still alive, so nothing to do / restart, just keep monitoring as normal
// scope.log("Bridge responded but was overloaded for now (ERR:429), no reconnection required for now.");
scope.startWatchdog();
}
});
} catch (error) {
scope.log("Lost connection with the bridge. Reconnect in some secs. " + error.message);
// scope.log("Lost connection with the bridge. Reconnect in some secs. " + error.message);
// debug
scope.log("Lost connection with the bridge. Reconnect in some secs. " + ((typeof(error.message) == 'undefined') ? JSON.stringify(error) : error.message));
// end debug
scope.start();
}
}, 10000);
Expand Down Expand Up @@ -337,11 +349,11 @@ module.exports = function(RED)

// GET CURRENT STATE MESSAGE
let currentState = message.msg;
return currentState;
return currentState;
} catch (error) {
return false;
}

}
else if(type == "light")
{
Expand Down Expand Up @@ -660,7 +672,7 @@ module.exports = function(RED)
//
// START THE MAGIC
this.start();

//
// CLOSE NODE / REMOVE EVENT LISTENER
this.on('close', function()
Expand Down Expand Up @@ -870,4 +882,4 @@ module.exports = function(RED)
});
}
});
};
};
8 changes: 4 additions & 4 deletions huemagic/hue-brightness.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -201,4 +201,4 @@ module.exports = function(RED)
}

RED.nodes.registerType("hue-brightness", HueBrightness);
}
}
26 changes: 13 additions & 13 deletions huemagic/hue-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -266,11 +266,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -349,11 +349,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -589,11 +589,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -633,4 +633,4 @@ module.exports = function(RED)
}

RED.nodes.registerType("hue-group", HueGroup);
}
}
26 changes: 13 additions & 13 deletions huemagic/hue-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -290,11 +290,11 @@ module.exports = function(RED)

// APPLY THE EFFECT
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -379,11 +379,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -818,11 +818,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -863,4 +863,4 @@ module.exports = function(RED)
}

RED.nodes.registerType("hue-light", HueLight);
}
}
6 changes: 3 additions & 3 deletions huemagic/hue-motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down
8 changes: 4 additions & 4 deletions huemagic/hue-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -157,4 +157,4 @@ module.exports = function(RED)
}

RED.nodes.registerType("hue-rules", HueRules);
}
}
12 changes: 6 additions & 6 deletions huemagic/hue-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ module.exports = function(RED)
{
// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -118,11 +118,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down
8 changes: 4 additions & 4 deletions huemagic/hue-temperature.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ module.exports = function(RED)

// PATCH!
async.retry({
times: 3,
times: 5,
errorFilter: function(err) {
return (err.status == 503);
return (err.status == 503 || err.status == 429);
},
interval: function(retryCount) { return retryCount*2000; }
interval: function(retryCount) { return 750*retryCount; }
},
function(callback, results)
{
Expand Down Expand Up @@ -205,4 +205,4 @@ module.exports = function(RED)
}

RED.nodes.registerType("hue-temperature", HueTemperature);
}
}
2 changes: 1 addition & 1 deletion huemagic/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function API()
const scope = this;
var fullResource = Object.assign({}, resource);

if(resource["owner"])
if(resource["owner"] && typeof allResources[fullResource["owner"]["rid"]] !== 'undefined')
{
fullResource = scope.fullResource(allResources[fullResource["owner"]["rid"]], allResources);
}
Expand Down
2 changes: 0 additions & 2 deletions huemagic/utils/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class HueGroupMessage
constructor(resource, options = {})
{
let service = Object.values(resource["services"]["grouped_light"])[0];
service = options.resources[service.id];

// GET ALL RESOURCES
let allResourcesInsideGroup = {};
Expand Down Expand Up @@ -454,4 +453,3 @@ class HueTemperatureMessage
//
// EXPORT
module.exports = { HueBridgeMessage, HueBrightnessMessage, HueGroupMessage, HueLightMessage, HueMotionMessage, HueRulesMessage, HueButtonsMessage, HueTemperatureMessage }

0 comments on commit f72d311

Please sign in to comment.