mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Tidy up pushbullet and prowl nodes. more error handling.
This commit is contained in:
parent
508ad7c3af
commit
c63583ae81
@ -31,7 +31,7 @@ catch(err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pushkey) {
|
if (pushkey) {
|
||||||
var prowl = new Prowl(pushkey.prowlkey);
|
if (pushkey.prowlkey) { var prowl = new Prowl(pushkey.prowlkey); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function ProwlNode(n) {
|
function ProwlNode(n) {
|
||||||
@ -44,11 +44,11 @@ function ProwlNode(n) {
|
|||||||
this.on("input",function(msg) {
|
this.on("input",function(msg) {
|
||||||
var titl = this.title||msg.topic||"Node-RED";
|
var titl = this.title||msg.topic||"Node-RED";
|
||||||
var pri = msg.priority||this.priority;
|
var pri = msg.priority||this.priority;
|
||||||
if (typeof(msg.payload) == 'object') {
|
if (typeof(msg.payload) === 'object') {
|
||||||
msg.payload = JSON.stringify(msg.payload);
|
msg.payload = JSON.stringify(msg.payload);
|
||||||
}
|
}
|
||||||
else { msg.payload = msg.payload.toString(); }
|
else { msg.payload = msg.payload.toString(); }
|
||||||
if (pushkey) {
|
if (pushkey.prowlkey) {
|
||||||
try {
|
try {
|
||||||
prowl.push(msg.payload, titl, { priority: pri }, function(err, remaining) {
|
prowl.push(msg.payload, titl, { priority: pri }, function(err, remaining) {
|
||||||
if (err) node.error(err);
|
if (err) node.error(err);
|
||||||
@ -64,5 +64,4 @@ function ProwlNode(n) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("prowl",ProwlNode);
|
RED.nodes.registerType("prowl",ProwlNode);
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<script type="text/x-red" data-help-name="pushbullet">
|
<script type="text/x-red" data-help-name="pushbullet">
|
||||||
<p>Uses PushBullet to push the <b>msg.payload</b> to an Android device that has PushBullet app installed.</p>
|
<p>Uses PushBullet to push the <b>msg.payload</b> to an Android device that has PushBullet app installed.</p>
|
||||||
<p>Optionally uses <b>msg.topic</b> to set the title, if not already set in the properties.</p>
|
<p>Optionally uses <b>msg.topic</b> to set the title, if not already set in the properties.</p>
|
||||||
<p>You MUST configure both your API key and the target device ID. Either into settings.js like this</p>
|
<p>You MUST configure both your <i>API key</i> and the target <i>device ID</i>. Either into settings.js like this</p>
|
||||||
<p><pre>pushbullet: { pushbullet:'My-API-KEY', deviceid:'xyzzyWabc' },</pre></p>
|
<p><pre>pushbullet: { pushbullet:'My-API-KEY', deviceid:'xyzzyWabc' },</pre></p>
|
||||||
<p>Or as a pushkey.js file in the directory <b>above</b> node-red.<p>
|
<p>Or as a pushkey.js file in the directory <b>above</b> node-red.<p>
|
||||||
<p><pre>module.exports = { pushbullet:'My-API-KEY', deviceid:'xyzzyWabc' }</pre></p>
|
<p><pre>module.exports = { pushbullet:'My-API-KEY', deviceid:'xyzzyWabc' }</pre></p>
|
||||||
@ -54,5 +54,4 @@
|
|||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -31,8 +31,8 @@ catch(err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pushkey) {
|
if (pushkey) {
|
||||||
var pusher = new PushBullet(pushkey.pushbullet);
|
if (pushkey.pushbullet) { var pusher = new PushBullet(pushkey.pushbullet); }
|
||||||
var deviceId = pushkey.deviceid;
|
if (pushkey.deviceid) { var deviceId = pushkey.deviceid; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function PushbulletNode(n) {
|
function PushbulletNode(n) {
|
||||||
@ -41,15 +41,16 @@ function PushbulletNode(n) {
|
|||||||
var node = this;
|
var node = this;
|
||||||
this.on("input",function(msg) {
|
this.on("input",function(msg) {
|
||||||
var titl = this.title||msg.topic||"Node-RED";
|
var titl = this.title||msg.topic||"Node-RED";
|
||||||
if (typeof(msg.payload) == 'object') {
|
if (typeof(msg.payload) === 'object') {
|
||||||
msg.payload = JSON.stringify(msg.payload);
|
msg.payload = JSON.stringify(msg.payload);
|
||||||
}
|
}
|
||||||
|
else { msg.payload = msg.payload.toString(); }
|
||||||
if (pushkey.pushbullet && pushkey.deviceid) {
|
if (pushkey.pushbullet && pushkey.deviceid) {
|
||||||
try {
|
try {
|
||||||
if (!isNaN(deviceId)) { deviceId = Number(deviceId); }
|
if (!isNaN(deviceId)) { deviceId = Number(deviceId); }
|
||||||
pusher.note(deviceId, titl, msg.payload, function(err, response) {
|
pusher.note(deviceId, titl, msg.payload, function(err, response) {
|
||||||
if (err) node.error(err);
|
if (err) node.error("Pushbullet error: "+err);
|
||||||
console.log(response);
|
//console.log(response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user