Skip to content

Commit 4a53c20

Browse files
committed
Update pushbullet to use latest 0.4 npm and allow iden as well as id
1 parent 66598a6 commit 4a53c20

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

social/pushbullet/57-pushbullet.html

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
</script>
2727

2828
<script type="text/x-red" data-help-name="pushbullet">
29-
<p>Uses PushBullet to push the <b>msg.payload</b> to an Android device that has PushBullet app installed.</p>
30-
<p>Optionally uses <b>msg.topic</b> to set the title, if not already set in the properties.</p>
31-
<p>You MUST configure both your API key and the target device ID. Either into settings.js like this</p>
32-
<p><pre>pushbullet: { pushbullet:'My-API-KEY', deviceid:'12345' },</pre></p>
33-
<p>Or as a pushkey.js file in the directory <b>above</b> node-red.<p>
34-
<p><pre>module.exports = { pushbullet:'My-API-KEY', deviceid:'12345' }</pre></p>
29+
<p>Uses PushBullet to push the <b>msg.payload</b> to an Android device that has PushBullet app installed.</p>
30+
<p>Optionally uses <b>msg.topic</b> to set the title, if not already set in the properties.</p>
31+
<p>You MUST configure both your API key and the target device ID. Either into settings.js like this</p>
32+
<p><pre>pushbullet: { pushbullet:'My-API-KEY', deviceid:'xyzzyWabc' },</pre></p>
33+
<p>Or as a pushkey.js file in the directory <b>above</b> node-red.<p>
34+
<p><pre>module.exports = { pushbullet:'My-API-KEY', deviceid:'xyzzyWabc' }</pre></p>
35+
<p>The deviceid can be found by hovering over you required device on the <a href="https://www.pushbullet.com/">PushBullet website</a>.</p>
3536
</script>
3637

3738
<script type="text/javascript">

social/pushbullet/57-pushbullet.js

+28-27
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,42 @@ var util = require('util');
2424
// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'}
2525

2626
try {
27-
var pushkey = RED.settings.pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js");
27+
var pushkey = RED.settings.pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js");
2828
}
2929
catch(err) {
30-
util.log("[57-pushbullet.js] Error: Failed to load PushBullet credentials");
30+
util.log("[57-pushbullet.js] Error: Failed to load PushBullet credentials");
3131
}
3232

3333
if (pushkey) {
34-
var pusher = new PushBullet(pushkey.pushbullet);
35-
var deviceId = pushkey.deviceid;
34+
var pusher = new PushBullet(pushkey.pushbullet);
35+
var deviceId = pushkey.deviceid;
3636
}
3737

3838
function PushbulletNode(n) {
39-
RED.nodes.createNode(this,n);
40-
this.title = n.title;
41-
var node = this;
42-
this.on("input",function(msg) {
43-
var titl = this.title||msg.topic||"Node-RED";
44-
if (typeof(msg.payload) == 'object') {
45-
msg.payload = JSON.stringify(msg.payload);
46-
}
47-
if (pushkey) {
48-
try {
49-
pusher.note(deviceId, titl, msg.payload, function(err, response) {
50-
if (err) node.error(err);
51-
console.log(response);
52-
});
53-
}
54-
catch (err) {
55-
node.error(err);
56-
}
57-
}
58-
else {
59-
node.warn("Pushbullet credentials not set/found. See node info.");
60-
}
61-
});
39+
RED.nodes.createNode(this,n);
40+
this.title = n.title;
41+
var node = this;
42+
this.on("input",function(msg) {
43+
var titl = this.title||msg.topic||"Node-RED";
44+
if (typeof(msg.payload) == 'object') {
45+
msg.payload = JSON.stringify(msg.payload);
46+
}
47+
if (pushkey.pushbullet && pushkey.deviceid) {
48+
try {
49+
if (!isNaN(deviceId)) { deviceId = Number(deviceId); }
50+
pusher.note(deviceId, titl, msg.payload, function(err, response) {
51+
if (err) node.error(err);
52+
console.log(response);
53+
});
54+
}
55+
catch (err) {
56+
node.error(err);
57+
}
58+
}
59+
else {
60+
node.warn("Pushbullet credentials not set/found. See node info.");
61+
}
62+
});
6263
}
6364

6465
RED.nodes.registerType("pushbullet",PushbulletNode);

0 commit comments

Comments
 (0)