Attempt to catch errors from wemo-lookup

This is to catch errors when device is offline
This commit is contained in:
Ben Hardill 2021-04-03 11:58:28 +01:00
parent 60fcbc351d
commit e9f0509cc6
No known key found for this signature in database
GPG Key ID: 74DD076979ABB1E7
3 changed files with 54 additions and 11 deletions

View File

@ -398,12 +398,17 @@ module.exports = function(RED) {
node.status({fill: 'green',shape: 'dot',text: 'found'});
}
node.on('input', function(msg) {
node.on('input', function(msg, send, done) {
var dev = wemo.get(node.dev);
send = send || function() { node.send.apply(node,arguments) }
if (!dev) {
//need to show that dev not currently found
console.log('no device found');
if (done) {
done()
}
return;
}
@ -427,7 +432,16 @@ module.exports = function(RED) {
delete status.capabilities;
// }
msg.payload = status;
node.send(msg);
send(msg);
if (done) {
done()
}
}).catch(function(err){
if (done) {
done(err)
} else {
node.error(err,msg)
}
});
} else if (dev.type === 'socket_insight') {
console.log("socket_insight");
@ -437,7 +451,16 @@ module.exports = function(RED) {
msg.payload = insightParameters;
// 'state' should be a number for backwards compatibility
msg.payload.state = parseInt(msg.payload.state);
node.send(msg);
send(msg);
if (done) {
done()
}
}).catch(function(err){
if (done) {
done(err)
} else {
node.error(err,msg)
}
});
} else {
console.log("socket");
@ -447,7 +470,17 @@ module.exports = function(RED) {
msg.payload = {
state: status
};
node.send(msg);
send(msg);
if (done) {
done()
}
})
.catch(function(err){
if (done) {
done(err)
} else {
node.error(err,msg)
}
});
}
});

View File

@ -5,7 +5,7 @@ var events = require('events');
var util = require('util');
var Client = require('node-ssdp').Client;
var xml2js = require('xml2js');
var request = require('request');
// var request = require('request');
var http = require('http');
var url = require('url');
var Q = require('q');
@ -271,6 +271,11 @@ WeMoNG.prototype.start = function start() {
post_request.abort();
});
post_request.on('error', function(err){
// should log err
console.log(err);
})
post_request.write(util.format(getenddevs.body, udn));
post_request.end();

View File

@ -1,6 +1,6 @@
{
"name": "node-red-node-wemo",
"version": "0.2.0",
"version": "0.2.1",
"description": "Input and Output nodes for Belkin WeMo devices",
"repository": "https://github.com/node-red/node-red-nodes/tree/master/hardware",
"main": "WeMoNG.js",
@ -12,11 +12,16 @@
"wemo",
"belkin"
],
"author": {
"email": "hardillb@gmail.com",
"name": "Benjamin Hardill",
"url": "http://www.hardill.me.uk/wordpress/"
},
"contributors": [
{
"email": "hardillb@gmail.com",
"name": "Benjamin Hardill",
"url": "http://www.hardill.me.uk/wordpress/"
},
{
"name": "Bart Butenaers"
}
],
"license": "Apache-2.0",
"dependencies": {
"node-ssdp": "~3.2.5",