1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fix chicken/egg with push alert nodes... couldn't see info about config until config was correct...

This commit is contained in:
Dave C-J 2013-10-01 19:13:02 +01:00
parent d332600149
commit 43ff2fa52b
4 changed files with 57 additions and 37 deletions

View File

@ -32,8 +32,10 @@
<script type="text/x-red" data-help-name="prowl"> <script type="text/x-red" data-help-name="prowl">
<p>Uses Prowl to push the <b>msg.payload</b> to an Apple device that has the prowl app installed.</p> <p>Uses Prowl to push the <b>msg.payload</b> to an Apple device that has the prowl app installed.</p>
<p>Optionally uses <b>msg.topic</b> to set the title. You can also set <b>msg.priority</b> to confgure the urgency from -2 (low), through 0 (normal) to 2 (urgent).</p> <p>Optionally uses <b>msg.topic</b> to set the title. You can also set <b>msg.priority</b> to confgure the urgency from -2 (low), through 0 (normal) to 2 (urgent).</p>
<p>You MUST configure your prowl API key into the pushkey.js file in the directory above node-red.</p> <p>You MUST configure your prowl API key into either the settings.js file like this</p>
<p><pre>module.exports = { prowl:'My-API-KEY' }</pre></p> <p><pre>prowl: { prowlkey:'My-API-KEY' },</pre></p>
<p>Or into a pushkey.js file in the directory <b>above</b> node-red.</p>
<p><pre>module.exports = { prowlkey:'My-API-KEY' }</pre></p>
<p>Uses Prowl so see <i><a href="https://www.prowlapp.com" target="_new">this link</a></i> for more details.</p> <p>Uses Prowl so see <i><a href="https://www.prowlapp.com" target="_new">this link</a></i> for more details.</p>
</script> </script>

View File

@ -16,17 +16,23 @@
var RED = require("../../red/red"); var RED = require("../../red/red");
var Prowl = require('node-prowl'); var Prowl = require('node-prowl');
var util = require('util');
// pushkey.js just needs to be like (with the quotes) // Either add a line like this to settings.js
// module.exports = {prowl:'My-API-KEY'} // prowl: {prowlkey:'My-API-KEY'},
// or create pushkey.js in dir ABOVE node-red, it just needs to be like
// module.exports = {prowlkey:'My-API-KEY'}
try { try {
var pushkey = require("../../settings").prowl || require("../../../pushkey.js"); var pushkey = require("../../settings").prowl || require("../../../pushkey.js");
} catch(err) { }
throw new Error("Failed to load Prowl credentials"); catch(err) {
util.log("[57-prowl.js] Error: Failed to load Prowl credentials");
} }
var prowl = new Prowl(pushkey.prowl); if (pushkey) {
var prowl = new Prowl(pushkey.prowlkey);
}
function ProwlNode(n) { function ProwlNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
@ -41,6 +47,7 @@ function ProwlNode(n) {
if (typeof(msg.payload) == 'object') { if (typeof(msg.payload) == 'object') {
msg.payload = JSON.stringify(msg.payload); msg.payload = JSON.stringify(msg.payload);
} }
if (pushkey) {
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);
@ -50,6 +57,10 @@ function ProwlNode(n) {
catch (err) { catch (err) {
node.error(err); node.error(err);
} }
}
else {
node.warn("Prowl credentials not set/found. See node info.");
}
}); });
} }

View File

@ -16,13 +16,9 @@
<script type="text/x-red" data-template-name="pushbullet"> <script type="text/x-red" data-template-name="pushbullet">
<div class="form-row"> <div class="form-row">
<label for="node-input-title"><i class="icon-tag"></i> Title</label> <label for="node-input-title"><i class="icon-flag"></i> Title</label>
<input type="text" id="node-input-title" placeholder="Node-RED"> <input type="text" id="node-input-title" placeholder="Node-RED">
</div> </div>
<div class="form-row">
<label for="node-input-priority"><i class="icon-tag"></i> Priority</label>
<input type="text" id="node-input-priority" placeholder="0">
</div>
<div class="form-row"> <div class="form-row">
<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">
@ -31,9 +27,11 @@
<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.</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 into the pushkey.js file in the directory above node-red.<p> <p>You MUST configure both your API key and the target device ID. Either into settings.js like this</p>
<p><pre>>module.exports = { pushbullet:'My-API-KEY', deviceid:'12345' }</pre</p> <p><pre>pushbullet: { pushbullet:'My-API-KEY', deviceid:'12345' },</pre></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:'12345' }</pre></p>
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
@ -41,7 +39,6 @@
category: 'output', category: 'output',
defaults: { defaults: {
title: {value:""}, title: {value:""},
priority: {value:0,required:true,validate:RED.validators.number()},
name: {value:""} name: {value:""}
}, },
color:"#a7c9a0", color:"#a7c9a0",

View File

@ -16,38 +16,48 @@
var RED = require("../../red/red"); var RED = require("../../red/red");
var PushBullet = require('pushbullet'); var PushBullet = require('pushbullet');
var util = require('util');
// pushkey.js just needs to be like (with the quotes) // Either add a line like this to settings.js
// pushbullet: {pushbullet:'My-API-KEY', deviceid:'12345'},
// or create pushkey.js in dir ABOVE node-red, it just needs to be like
// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'} // module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'}
try { try {
var pushkey = require("../../settings").pushbullet || require("../../../pushkey.js"); var pushkey = require("../../settings").pushbullet || require("../../../pushkey.js");
} catch(err) { }
throw new Error("Failed to load PushBullet credentials"); catch(err) {
util.log("[57-pushbullet.js] Error: Failed to load PushBullet credentials");
} }
if (pushkey) {
var pusher = new PushBullet(pushkey.pushbullet); var pusher = new PushBullet(pushkey.pushbullet);
var deviceId = pushkey.deviceid; var deviceId = pushkey.deviceid;
}
function PushbulletNode(n) { function PushbulletNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.title = n.title; this.title = n.title;
this.device
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);
} }
if (pushkey) {
try { try {
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(err);
node.log( JSON.stringify(response) ); console.log(response);
}); });
} }
catch (err) { catch (err) {
node.error(err); node.error(err);
} }
}
else {
node.warn("Pushbullet credentials not set/found. See node info.");
}
}); });
} }