@@ -108,29 +108,32 @@ module.exports = function (RED) {
108108 node . on ( 'input' , async function ( ) {
109109 const now = moment ( ) ;
110110 const end = now . format ( ) ;
111- const start = now . subtract ( this . timeWindowCount * this . timeWindowUnit , 'second' ) . format ( ) ;
112- await connectionManager . connect ( connectionConfig ) ;
113- const result = await this . arduinoRestClient . getSeries ( this . thing , this . propertyId , start , end ) ;
114- const times = result . responses [ 0 ] . times ;
115- const values = result . responses [ 0 ] . values ;
116- let data = [ ] ;
117- if ( values && times ) {
118- values . forEach ( function ( item , index , array ) {
119- data . push ( {
120- x : moment ( times [ index ] ) . unix ( ) * 1000 ,
121- y : values [ index ]
111+ const count = this . timeWindowCount
112+ if ( count !== null && count !== "" && count !== undefined && Number . isInteger ( parseInt ( count ) ) && parseInt ( count ) !== 0 ) {
113+ const start = now . subtract ( count * this . timeWindowUnit , 'second' ) . format ( ) ;
114+ await connectionManager . connect ( connectionConfig ) ;
115+ const result = await this . arduinoRestClient . getSeries ( this . thing , this . propertyId , start , end ) ;
116+ const times = result . responses [ 0 ] . times ;
117+ const values = result . responses [ 0 ] . values ;
118+ let data = [ ] ;
119+ if ( values && times ) {
120+ values . forEach ( function ( item , index , array ) {
121+ data . push ( {
122+ x : moment ( times [ index ] ) . unix ( ) * 1000 ,
123+ y : values [ index ]
124+ } ) ;
122125 } ) ;
123- } ) ;
124- }
125- node . send (
126- {
127- topic : config . name ,
128- payload : [ {
129- series : [ ] ,
130- data : [ data ]
131- } ]
132126 }
133- ) ;
127+ node . send (
128+ {
129+ topic : config . name ,
130+ payload : [ {
131+ series : [ ] ,
132+ data : [ data ]
133+ } ]
134+ }
135+ ) ;
136+ }
134137 } ) ;
135138 }
136139 } catch ( err ) {
@@ -157,7 +160,9 @@ module.exports = function (RED) {
157160 this . propertyId = config . property ;
158161 this . propertyName = config . name ;
159162 const pollTime = this . timeWindowCount * this . timeWindowUnit ;
160- this . poll ( connectionConfig , pollTime ) ;
163+ if ( pollTime !== null && pollTime !== "" && pollTime !== undefined && Number . isInteger ( parseInt ( pollTime ) ) && parseInt ( pollTime ) !== 0 ) {
164+ this . poll ( connectionConfig , pollTime ) ;
165+ }
161166 }
162167 } catch ( err ) {
163168 console . log ( err ) ;
0 commit comments