mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Pushbullet changes to make it more obvious what it is now doing...
(and fix a couple of things it wasn't)
This commit is contained in:
parent
4be0e05c2a
commit
5b28f06510
@ -32,13 +32,15 @@
|
|||||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-tips" id="node-tip"><b>Note:</b> Using credentials from global pushkey.js file.</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<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 the 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 <i>API key</i> and the target <i>device ID</i>. You can set these per node in the edit dialog
|
<p>You need to configure both your <i>API key</i> and the target <i>device ID</i>.
|
||||||
or as a pushkey.js file in the directory <b>above</b> node-red.<p>
|
The device ID may be passed in as <b>msg.deviceid</b>. You can set these per node in the edit dialog.
|
||||||
|
The old method of storing your credentials in the pushkey.js file in the directory <b>above</b> /node-red is being deprecated.</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>
|
||||||
<p>The deviceid can be found by hovering over your required device on the <a href="https://www.pushbullet.com/">PushBullet website</a>.</p>
|
<p>The deviceid can be found by hovering over your required device on the <a href="https://www.pushbullet.com/">PushBullet website</a>.</p>
|
||||||
</script>
|
</script>
|
||||||
@ -71,7 +73,8 @@
|
|||||||
} else {
|
} else {
|
||||||
$('#node-config-input-pushkey').val('');
|
$('#node-config-input-pushkey').val('');
|
||||||
}
|
}
|
||||||
|
if (data.global) $('#node-tip').show();
|
||||||
|
else $('#node-tip').hide();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
oneditsave: function() {
|
oneditsave: function() {
|
||||||
|
@ -36,30 +36,30 @@ function PushbulletNode(n) {
|
|||||||
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
|
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
|
||||||
else {
|
else {
|
||||||
if (pushkeys) { this.pushkey = pushkeys.pushbullet; }
|
if (pushkeys) { this.pushkey = pushkeys.pushbullet; }
|
||||||
else { this.error("No credentials set"); }
|
else { this.error("No Pushbullet API key set"); }
|
||||||
}
|
}
|
||||||
if ((credentials) && (credentials.hasOwnProperty("deviceid"))) { this.deviceid = credentials.deviceid; }
|
if ((credentials) && (credentials.hasOwnProperty("deviceid"))) { this.deviceid = credentials.deviceid; }
|
||||||
else {
|
else {
|
||||||
if (pushkeys) { this.deviceid = pushkeys.deviceid; }
|
if (pushkeys) { this.deviceid = pushkeys.deviceid; }
|
||||||
else { this.warn("No deviceId set"); }
|
else { this.warn("No deviceid set"); }
|
||||||
}
|
}
|
||||||
//console.log("Cred:",n.id,this.deviceid,this.pushkey);
|
|
||||||
this.pusher = new PushBullet(this.pushkey);
|
this.pusher = new PushBullet(this.pushkey);
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
this.on("input",function(msg) {
|
this.on("input",function(msg) {
|
||||||
var titl = node.title||msg.topic||"Node-RED";
|
var titl = node.title||msg.topic||"Node-RED";
|
||||||
var dev = msg.deviceID||node.deviceId;
|
var dev = msg.deviceid||node.deviceid;
|
||||||
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 (node.pushkey && node.deviceid) {
|
if (node.pushkey && dev) {
|
||||||
|
console.log(node.pushkey,dev);
|
||||||
try {
|
try {
|
||||||
if (!isNaN(node.deviceId)) { node.deviceId = Number(node.deviceId); }
|
if (!isNaN(dev)) { dev = Number(dev); }
|
||||||
node.pusher.note(dev, titl, msg.payload, function(err, response) {
|
node.pusher.note(dev, titl, msg.payload, function(err, response) {
|
||||||
if (err) node.error("Pushbullet error: "+err);
|
if (err) node.error("Pushbullet error: "+err);
|
||||||
//console.log(response);
|
console.log(response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
@ -79,7 +79,13 @@ RED.httpAdmin.get('/pushbullet/:id',function(req,res) {
|
|||||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));
|
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));
|
||||||
} else {
|
}
|
||||||
|
else if (pushkeys && pushkeys.pushbullet && pushkeys.deviceid) {
|
||||||
|
RED.nodes.addCredentials(req.params.id,{pushkey:pushkeys.pushbullet,deviceid:pushkeys.deviceid,global:true});
|
||||||
|
credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
|
res.send(JSON.stringify({deviceid:credentials.deviceid,global:credentials.global,hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));;
|
||||||
|
}
|
||||||
|
else {
|
||||||
res.send(JSON.stringify({}));
|
res.send(JSON.stringify({}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user