Add device target bailty to pushover node

This commit is contained in:
Dave Conway-Jones 2015-08-25 21:04:54 +01:00
parent 834115907c
commit 4e6f76cc1d
4 changed files with 19 additions and 8 deletions

View File

@ -19,6 +19,10 @@
<label for="node-input-title"><i class="fa fa-flag"></i> Title</label>
<input type="text" id="node-input-title" placeholder="Node-RED">
</div>
<div class="form-row">
<label for="node-input-device"><i class="fa fa-mobile"></i> Device</label>
<input type="text" id="node-input-device" placeholder="leave blank for all">
</div>
<div class="form-row">
<label for="node-input-priority"><i class="fa fa-star"></i> Priority</label>
<input type="text" id="node-input-priority" placeholder="0" style="width:50px;">
@ -36,13 +40,15 @@
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-tips" id="node-tip">Tip: Leave title blank to set using <b>msg.topic</b> and <b>msg.priority</b>.<br/>
Supports priorities 2, 1, 0, -1, and -2.</div>
<div class="form-tips" id="node-tip">Tip: Leave title blank to set using <b>msg.topic</b>.<br/>
Leave device blank to send to all devices, or to set using <b>msg.device</b>.<br/>
Leave priority blank to set using <b>msg.priority</b>. Supports priorities 2, 1, 0, -1, and -2.</div>
</script>
<script type="text/x-red" data-help-name="pushover">
<p>Uses Pushover to push the <b>msg.payload</b> to a device that has the Pushover app installed.</p>
<p>Optionally uses <b>msg.topic</b> to set the title, and <b>msg.priority</b> to set the priority, if not already set in the properties.</p>
<p>Optionally uses <b>msg.topic</b> to set the title, <b>msg.device</b> to set the device, and <b>msg.priority</b>
to set the priority, if not already set in the properties.</p>
<p>The User-key and API-token are stored in a separate credentials file.</p>
<p>Uses Pushover. See <i><a href="https://pushover.net" target="_new">this link</a></i> for more details.</p>
</script>
@ -51,8 +57,9 @@
RED.nodes.registerType('pushover',{
category: 'output',
defaults: {
title: {value:""},
name: {value:""},
device: {value:""},
title: {value:""},
priority: {value:0}
},
credentials: {
@ -72,7 +79,7 @@
},
oneditprepare: function() {
$("#node-input-priority").spinner({
min:-1,
min:-2,
max:2
});
}

View File

@ -22,6 +22,7 @@ module.exports = function(RED) {
function PushoverNode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
this.device = n.device;
this.priority = n.priority;
var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
@ -43,6 +44,7 @@ module.exports = function(RED) {
this.on("input",function(msg) {
var titl = this.title || msg.topic || "Node-RED";
var pri = this.priority || msg.priority || 0;
var dev = this.device || msg.device;
if (isNaN(pri)) {pri=0;}
if (pri > 2) {pri = 2;}
if (pri < -2) {pri = -2;}
@ -58,7 +60,8 @@ module.exports = function(RED) {
retry: 30,
expire: 600
};
//console.log("Sending",pushmsg);
if (dev) { pushmsg.device = dev; }
//node.log("Sending "+JSON.stringify(pushmsg));
pusher.send( pushmsg, function(err, response) {
if (err) { node.error("Pushover Error: "+err); }
//console.log(response);

View File

@ -16,7 +16,8 @@ Usage
Uses Pushover to push the <b>msg.payload</b> to a device that has the Pushover app installed.
Optionally uses **msg.topic** to set the title, and **msg.priority** to set the priority, if not already set in the properties.
Optionally uses **msg.topic** to set the title, **msg.device** to set the device
and **msg.priority** to set the priority, if not already set in the properties.
The User-key and API-token are stored in a separate credentials file.

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-pushover",
"version" : "0.0.4",
"version" : "0.0.5",
"description" : "A Node-RED node to send alerts via Pushover",
"dependencies" : {
"pushover-notifications" : "0.2.2"