@@ -108,29 +108,32 @@ module.exports = function (RED) {
108
108
node . on ( 'input' , async function ( ) {
109
109
const now = moment ( ) ;
110
110
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
+ } ) ;
122
125
} ) ;
123
- } ) ;
124
- }
125
- node . send (
126
- {
127
- topic : config . name ,
128
- payload : [ {
129
- series : [ ] ,
130
- data : [ data ]
131
- } ]
132
126
}
133
- ) ;
127
+ node . send (
128
+ {
129
+ topic : config . name ,
130
+ payload : [ {
131
+ series : [ ] ,
132
+ data : [ data ]
133
+ } ]
134
+ }
135
+ ) ;
136
+ }
134
137
} ) ;
135
138
}
136
139
} catch ( err ) {
@@ -157,7 +160,9 @@ module.exports = function (RED) {
157
160
this . propertyId = config . property ;
158
161
this . propertyName = config . name ;
159
162
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
+ }
161
166
}
162
167
} catch ( err ) {
163
168
console . log ( err ) ;
0 commit comments