@@ -24,41 +24,42 @@ var util = require('util');
2424// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'}
2525
2626try {
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}
2929catch ( 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
3333if ( 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
3838function 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
6465RED . nodes . registerType ( "pushbullet" , PushbulletNode ) ;
0 commit comments