From c63583ae81566e7714cd3d1ecd4bcf0f07150f64 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sun, 2 Mar 2014 18:19:11 +0000 Subject: [PATCH] Tidy up pushbullet and prowl nodes. more error handling. --- social/prowl/57-prowl.js | 7 +++---- social/pushbullet/57-pushbullet.html | 3 +-- social/pushbullet/57-pushbullet.js | 11 ++++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/social/prowl/57-prowl.js b/social/prowl/57-prowl.js index 9d8801bc..ee1791c2 100644 --- a/social/prowl/57-prowl.js +++ b/social/prowl/57-prowl.js @@ -31,7 +31,7 @@ catch(err) { } if (pushkey) { - var prowl = new Prowl(pushkey.prowlkey); + if (pushkey.prowlkey) { var prowl = new Prowl(pushkey.prowlkey); } } function ProwlNode(n) { @@ -44,11 +44,11 @@ function ProwlNode(n) { this.on("input",function(msg) { var titl = this.title||msg.topic||"Node-RED"; var pri = msg.priority||this.priority; - if (typeof(msg.payload) == 'object') { + if (typeof(msg.payload) === 'object') { msg.payload = JSON.stringify(msg.payload); } else { msg.payload = msg.payload.toString(); } - if (pushkey) { + if (pushkey.prowlkey) { try { prowl.push(msg.payload, titl, { priority: pri }, function(err, remaining) { if (err) node.error(err); @@ -64,5 +64,4 @@ function ProwlNode(n) { } }); } - RED.nodes.registerType("prowl",ProwlNode); diff --git a/social/pushbullet/57-pushbullet.html b/social/pushbullet/57-pushbullet.html index dda75be5..4008321f 100644 --- a/social/pushbullet/57-pushbullet.html +++ b/social/pushbullet/57-pushbullet.html @@ -28,7 +28,7 @@ diff --git a/social/pushbullet/57-pushbullet.js b/social/pushbullet/57-pushbullet.js index cb6583d1..a172490d 100644 --- a/social/pushbullet/57-pushbullet.js +++ b/social/pushbullet/57-pushbullet.js @@ -31,8 +31,8 @@ catch(err) { } if (pushkey) { - var pusher = new PushBullet(pushkey.pushbullet); - var deviceId = pushkey.deviceid; + if (pushkey.pushbullet) { var pusher = new PushBullet(pushkey.pushbullet); } + if (pushkey.deviceid) { var deviceId = pushkey.deviceid; } } function PushbulletNode(n) { @@ -41,15 +41,16 @@ function PushbulletNode(n) { var node = this; this.on("input",function(msg) { var titl = this.title||msg.topic||"Node-RED"; - if (typeof(msg.payload) == 'object') { + if (typeof(msg.payload) === 'object') { msg.payload = JSON.stringify(msg.payload); } + else { msg.payload = msg.payload.toString(); } if (pushkey.pushbullet && pushkey.deviceid) { try { if (!isNaN(deviceId)) { deviceId = Number(deviceId); } pusher.note(deviceId, titl, msg.payload, function(err, response) { - if (err) node.error(err); - console.log(response); + if (err) node.error("Pushbullet error: "+err); + //console.log(response); }); } catch (err) {