@@ -168,13 +168,13 @@ module.exports = function(RED) {
168168 type : this . types
169169 } ;
170170 if ( ( this . beginDate !== '' ) && ( this . beginDate !== null ) ) {
171- options . date_begin = JSON . parse ( this . beginDate )
171+ options . date_begin = JSON . parse ( this . beginDate ) ;
172172 }
173173 if ( ( this . endDate !== '' ) && ( this . endDate !== null ) ) {
174- options . date_end = ( this . endDate === 'last' ? 'last' : JSON . parse ( this . endDate ) )
174+ options . date_end = ( this . endDate === 'last' ? 'last' : JSON . parse ( this . endDate ) ) ;
175175 }
176176 if ( ( this . limit !== '' ) && ( this . limit !== null ) ) {
177- options . limit = JSON . parse ( this . limit )
177+ options . limit = JSON . parse ( this . limit ) ;
178178 }
179179
180180 api . getMeasure ( options , function ( err , measure ) {
@@ -219,6 +219,59 @@ module.exports = function(RED) {
219219 }
220220 RED . nodes . registerType ( "get stations data" , NetatmoGetStationsData ) ;
221221 /***************************************************************/
222+ function NetatmoGetPublicData ( config ) {
223+ RED . nodes . createNode ( this , config ) ;
224+ this . creds = RED . nodes . getNode ( config . creds ) ;
225+ var node = this ;
226+ this . on ( 'input' , function ( msg ) {
227+ config . lat_ne = config . lat_ne || '15' ;
228+ config . lon_ne = config . lon_ne || '20' ;
229+ config . lat_sw = config . lat_sw || '-15' ;
230+ config . lon_sw = config . lon_sw || '-20' ;
231+ config . required_data = config . required_data || 'rain,humidity' ;
232+ config . filter = config . filter || false ;
233+ this . lat_ne = mustache . render ( config . lat_ne , msg ) ;
234+ this . lon_ne = mustache . render ( config . lon_ne , msg ) ;
235+ this . lat_sw = mustache . render ( config . lat_sw , msg ) ;
236+ this . lon_sw = mustache . render ( config . lon_sw , msg ) ;
237+ this . required_data = mustache . render ( config . required_data , msg ) ;
238+ this . filter = mustache . render ( config . filter , msg ) ;
239+ var netatmo = require ( 'netatmo' ) ;
240+
241+ var auth = {
242+ "client_id" : this . creds . client_id ,
243+ "client_secret" : this . creds . client_secret ,
244+ "username" : this . creds . username ,
245+ "password" : this . creds . password
246+ } ;
247+ var api = new netatmo ( auth ) ;
248+
249+ api . on ( "error" , function ( error ) {
250+ node . error ( error ) ;
251+ } ) ;
252+
253+ api . on ( "warning" , function ( error ) {
254+ node . warn ( error ) ;
255+ } ) ;
256+
257+ var options = {
258+ lat_ne : config . lat_ne ,
259+ lon_ne : config . lon_ne ,
260+ lat_sw : config . lat_sw ,
261+ lon_sw : config . lon_sw ,
262+ required_data : config . required_data ,
263+ filter : config . filter ,
264+ } ;
265+
266+ api . getPublicData ( options , function ( err , data ) {
267+ msg . payload = data ;
268+ node . send ( msg ) ;
269+ } ) ;
270+ } ) ;
271+
272+ }
273+ RED . nodes . registerType ( "get public data" , NetatmoGetPublicData ) ;
274+ /***************************************************************/
222275 function NetatmoConfigNode ( n ) {
223276 RED . nodes . createNode ( this , n ) ;
224277 this . client_id = n . client_id ;
0 commit comments