homebridge-cmd4 6.3.0 → 7.0.0-beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -32
- package/Cmd4Accessory.js +19 -86
- package/Cmd4Platform.js +0 -55
- package/Cmd4PriorityPollingQueue.js +246 -90
- package/Cmd4PriorityPollingQueue.js.1 +1148 -0
- package/Extras/config.json +110 -110
- package/Extras/config.min.json +111 -111
- package/RUNNING_CHANGELOG.md +48 -0
- package/cmd4Constants.js +56 -2
- package/docs/Developers.md +21 -23
- package/package.json +1 -1
|
@@ -31,7 +31,7 @@ let LOW_PRIORITY_GET = 2;
|
|
|
31
31
|
|
|
32
32
|
class Cmd4PriorityPollingQueue
|
|
33
33
|
{
|
|
34
|
-
constructor( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE )
|
|
34
|
+
constructor( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE, queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT )
|
|
35
35
|
{
|
|
36
36
|
this.log = log;
|
|
37
37
|
|
|
@@ -40,6 +40,7 @@ class Cmd4PriorityPollingQueue
|
|
|
40
40
|
|
|
41
41
|
this.queueName = queueName;
|
|
42
42
|
this.queueType = queueType;
|
|
43
|
+
this.queueRetryCount = queueRetryCount;
|
|
43
44
|
this.queueStarted = false;
|
|
44
45
|
this.highPriorityQueue = [ ];
|
|
45
46
|
this.lowPriorityQueue = [ ];
|
|
@@ -64,73 +65,121 @@ class Cmd4PriorityPollingQueue
|
|
|
64
65
|
// The WoRm queue needs error messages to be silenced as
|
|
65
66
|
// they are inevitable, but are handled through retries
|
|
66
67
|
// By default non WoRm queues are allowed to echo errors
|
|
67
|
-
|
|
68
|
+
|
|
69
|
+
if ( this.queueRetryCount == 0 || settings.debug )
|
|
70
|
+
this.echoE = true;
|
|
71
|
+
else
|
|
72
|
+
this.echoE = true;
|
|
68
73
|
|
|
69
74
|
this.changeQueueType( this, queueType );
|
|
70
75
|
}
|
|
71
76
|
|
|
72
|
-
|
|
77
|
+
echoRetryErrors( currentRetryCount )
|
|
73
78
|
{
|
|
74
|
-
|
|
79
|
+
// If debug then the default is true
|
|
80
|
+
if ( settings.cmd4Debug )
|
|
81
|
+
return true;
|
|
82
|
+
|
|
83
|
+
// Since this is the last retry, echo the error
|
|
84
|
+
if ( currentRetryCount == this.queueRetryCount )
|
|
85
|
+
return true;
|
|
86
|
+
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// This function is called by homebridge to *PUT AN ENTRY INTO THE HIGHEST PRIORITY SET QUEUE*.
|
|
91
|
+
// We immediately return success if the device is accessible. Either way the Set is attempted
|
|
92
|
+
// above everything else except other SetValue requests.
|
|
93
|
+
prioritySetValue( accTypeEnumIndex, characteristicString, timeout, stateChangeResponseTime, value, homebridgeCallback )
|
|
94
|
+
{
|
|
95
|
+
// this is Accessory
|
|
96
|
+
//
|
|
97
|
+
//if ( settings.cmd4Dbg ) this.log.debug(`prioritySetValue, asked to set: ${ characteristicString } to ${ value }`);
|
|
75
98
|
|
|
76
99
|
// Save the value to cache. The set will come later
|
|
77
|
-
|
|
78
|
-
|
|
100
|
+
// this.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, value );
|
|
101
|
+
|
|
102
|
+
if ( this.errorValue != 0 )
|
|
103
|
+
{
|
|
104
|
+
if ( settings.cmd4Dbg ) this.log.debug(`prioritySetValue for ${ this.displayName }, homebridgeCallback returning error ${ this.errorValue } ${ this.errorString }`);
|
|
105
|
+
homebridgeCallback( this.errorValue );
|
|
106
|
+
} else
|
|
107
|
+
{
|
|
108
|
+
if ( settings.cmd4Dbg ) this.log.debug(`prioritySetValue for ${ this.displayName }, homebridgeCallback returning default success 0`);
|
|
109
|
+
homebridgeCallback( 0 );
|
|
110
|
+
}
|
|
79
111
|
|
|
80
|
-
let newEntry = { [ constants.IS_SET_lv ]: true, [ constants.ACCESSORY_lv ]:
|
|
112
|
+
let newEntry = { [ constants.IS_SET_lv ]: true, [ constants.ACCESSORY_lv ]: this, [ constants.ACC_TYPE_ENUM_INDEX_lv ]: accTypeEnumIndex, [ constants.CHARACTERISTIC_STRING_lv ]: characteristicString, [ constants.TIMEOUT_lv ]: timeout, [ constants.STATE_CHANGE_RESPONSE_TIME_lv ]: stateChangeResponseTime, [ constants.CALLBACK_lv ]: homebridgeCallback, [ constants.VALUE_lv ]: value };
|
|
81
113
|
|
|
82
114
|
// Determine where to put the entry in the queue
|
|
83
|
-
if (
|
|
115
|
+
if ( this.queue.highPriorityQueue.length == 0 )
|
|
84
116
|
{
|
|
85
117
|
// No entries, then it goes on top
|
|
86
|
-
|
|
118
|
+
this.queue.highPriorityQueue.push( newEntry );
|
|
87
119
|
|
|
88
120
|
} else {
|
|
89
121
|
|
|
90
122
|
// Make sure that this is the latest "Set" of this entry
|
|
91
|
-
let index =
|
|
123
|
+
let index = this.queue.highPriorityQueue.findIndex( ( entry ) => entry.accessory.uuid == this.uuid && entry.isSet == true && entry.accTypeEnumIndex == accTypeEnumIndex );
|
|
92
124
|
|
|
93
125
|
if ( index == -1 )
|
|
94
126
|
{
|
|
95
127
|
// It doesn't exist in the queue, It needs to be placed after any "Sets".
|
|
96
128
|
// First Determine the first "Get"
|
|
97
|
-
let getIndex =
|
|
129
|
+
let getIndex = this.queue.highPriorityQueue.findIndex( ( entry ) => entry.isSet == false );
|
|
98
130
|
|
|
99
131
|
if ( getIndex == -1 )
|
|
100
132
|
{
|
|
101
133
|
// No "Get" entrys, it goes at the end after everything.
|
|
102
|
-
|
|
134
|
+
this.queue.highPriorityQueue.push( newEntry );
|
|
103
135
|
|
|
104
136
|
} else
|
|
105
137
|
{
|
|
106
138
|
// Insert before the first "Get" entry
|
|
107
|
-
|
|
139
|
+
this.queue.highPriorityQueue.splice( getIndex, 0, newEntry );
|
|
108
140
|
}
|
|
109
141
|
} else
|
|
110
142
|
{
|
|
111
|
-
|
|
143
|
+
this.queue.highPriorityQueue[ index ] = newEntry;
|
|
112
144
|
}
|
|
113
145
|
}
|
|
114
|
-
|
|
146
|
+
this.queue.processQueueFunc( HIGH_PRIORITY_SET, this.queue );
|
|
115
147
|
}
|
|
116
148
|
|
|
117
|
-
|
|
149
|
+
// This function is called by homebridge to *PUT AN ENTRY INTO THE HIGHEST PRIORITY GET QUEUE*.
|
|
150
|
+
// We immediately return with success and the last known value if the device is accessible, otherwise
|
|
151
|
+
// the last failure error code.
|
|
152
|
+
// The Get is attempted no matter the devices availability. This is done after every Set
|
|
153
|
+
// request and at the bottom of the hightPrioritySetValue queue, but above any polling.
|
|
154
|
+
priorityGetValue( accTypeEnumIndex, characteristicString, timeout, homebridgeCallback )
|
|
118
155
|
{
|
|
119
|
-
|
|
156
|
+
// this is Accessory
|
|
120
157
|
|
|
121
|
-
//
|
|
122
|
-
let storedValue = self.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex );
|
|
123
|
-
callback( 0, storedValue );
|
|
158
|
+
// if ( settings.cmd4Dbg ) this.log.debug(`priorityGetValue for ${ this.displayName }, asked to Get: ${ characteristicString }`);
|
|
124
159
|
|
|
125
|
-
if (
|
|
160
|
+
if ( this.errorValue != 0 )
|
|
161
|
+
{
|
|
162
|
+
// if ( settings.cmd4Dbg ) this.log.debug(`priorityGetValue for ${ this.displayName }, homebridgeCallback returning error ${ this.errorValue } ${ this.errorString}`);
|
|
163
|
+
homebridgeCallback( this.errorValue );
|
|
164
|
+
} else
|
|
165
|
+
{
|
|
166
|
+
// return the cached value
|
|
167
|
+
let storedValue = this.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex );
|
|
168
|
+
|
|
169
|
+
// if ( settings.cmd4Dbg ) this.log.debug(`priorityGetValue for ${ this.displayName }, homebridgeCallback returning storedValue: ${ storedValue }`);
|
|
170
|
+
homebridgeCallback( 0, storedValue );
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if ( this.queue.queueType != constants.QUEUETYPE_WORM2 )
|
|
126
174
|
{
|
|
127
175
|
// When the value is returned, it will update homebridge
|
|
128
|
-
|
|
176
|
+
this.queue.highPriorityQueue.push( { [ constants.IS_SET_lv ]: false, [ constants.QUEUE_GET_IS_UPDATE_lv ]: true, [ constants.ACCESSORY_lv ]: this, [ constants.ACC_TYPE_ENUM_INDEX_lv ]: accTypeEnumIndex, [ constants.CHARACTERISTIC_STRING_lv ]: characteristicString, [ constants.TIMEOUT_lv ]: timeout, [ constants.STATE_CHANGE_RESPONSE_TIME_lv ]: null, [ constants.VALUE_lv ]: null, [ constants.CALLBACK_lv ]: homebridgeCallback } );
|
|
129
177
|
|
|
130
|
-
|
|
178
|
+
this.queue.processQueueFunc( HIGH_PRIORITY_GET, this.queue );
|
|
131
179
|
}
|
|
132
180
|
}
|
|
133
181
|
|
|
182
|
+
// This function is called by polling to *PUT AN ENTRY INTO THE LOW PRIORITY POLLING QUEUE*.
|
|
134
183
|
addLowPriorityGetPolledQueueEntry( accessory, accTypeEnumIndex, characteristicString, interval, timeout )
|
|
135
184
|
{
|
|
136
185
|
// These are all gets from polling
|
|
@@ -148,28 +197,34 @@ class Cmd4PriorityPollingQueue
|
|
|
148
197
|
|
|
149
198
|
let queue = entry.accessory.queue;
|
|
150
199
|
|
|
200
|
+
// Save the error code - Pass or fail
|
|
201
|
+
entry.accessory.errorValue = error;
|
|
202
|
+
|
|
151
203
|
if ( error == 0 )
|
|
152
204
|
{
|
|
205
|
+
// Now that the set was successful, store the value
|
|
206
|
+
entry.accessory.cmd4Storage.setStoredValueForIndex( entry.accTypeEnumIndex, entry.value );
|
|
207
|
+
|
|
153
208
|
// Since the "Set" passed, do the stateChangeResponseTime
|
|
154
209
|
setTimeout( ( ) =>
|
|
155
210
|
{
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
211
|
+
// A set with no error means the queue is sane to do reading
|
|
212
|
+
queue.lastGoodTransactionTime = Date.now( );
|
|
213
|
+
queue.errorCountSinceLastGoodTransaction = 0;
|
|
159
214
|
|
|
160
|
-
|
|
161
|
-
|
|
215
|
+
// After the stateChangeResponseTime, do the related characteristic ( if any )
|
|
216
|
+
let relatedCurrentAccTypeEnumIndex = entry.accessory.getDevicesRelatedCurrentAccTypeEnumIndex( entry.accTypeEnumIndex );
|
|
162
217
|
|
|
163
218
|
if ( relatedCurrentAccTypeEnumIndex != null )
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
219
|
+
{
|
|
220
|
+
let relatedCurrentCharacteristicString = CMD4_ACC_TYPE_ENUM.properties[ relatedCurrentAccTypeEnumIndex ].type;
|
|
221
|
+
// Change the entry to a get and set queueGetIsUpdate to true
|
|
222
|
+
// Use unshift to make it next in line
|
|
223
|
+
entry.isSet = false;
|
|
224
|
+
entry.accTypeEnumIndex = relatedCurrentAccTypeEnumIndex;
|
|
225
|
+
entry.characteristicString = relatedCurrentCharacteristicString;
|
|
226
|
+
entry.queueGetIsUpdate = true;
|
|
227
|
+
queue.highPriorityQueue.unshift( entry );
|
|
173
228
|
}
|
|
174
229
|
|
|
175
230
|
// The "Set" is now complete after its stateChangeResponseTime.
|
|
@@ -177,24 +232,43 @@ class Cmd4PriorityPollingQueue
|
|
|
177
232
|
|
|
178
233
|
setTimeout( ( ) => { queue.processQueueFunc( HIGH_PRIORITY_GET, queue ); }, 0 );
|
|
179
234
|
|
|
180
|
-
|
|
235
|
+
return;
|
|
181
236
|
|
|
182
237
|
}, entry.stateChangeResponseTime );
|
|
183
238
|
|
|
184
239
|
} else // setValue failed
|
|
185
240
|
{
|
|
186
|
-
|
|
187
241
|
// The "Set" is complete, even if it failed.
|
|
188
242
|
queue.inProgressSets --;
|
|
189
243
|
|
|
190
|
-
|
|
191
|
-
queue.highPriorityQueue.push( entry );
|
|
244
|
+
let currentRetryCount = queue.errorCountSinceLastGoodTransaction;
|
|
192
245
|
|
|
193
|
-
queue.
|
|
194
|
-
|
|
246
|
+
if ( currentRetryCount >= queue.queueRetryCount )
|
|
247
|
+
{
|
|
248
|
+
if ( queue.echoRetryErrors( currentRetryCount ) )
|
|
249
|
+
{
|
|
250
|
+
// Counting starts from zero, i.e queueRetries = 0, so add 1
|
|
251
|
+
queue.log.warn( `*${ currentRetryCount + 1 }* error(s) were encountered for "${ entry.accessory.displayName }" getValue. Last error found Getting: "${ entry.characteristicString}". Perhaps you should run in debug mode to find out what the problem might be.` );
|
|
252
|
+
}
|
|
195
253
|
|
|
196
|
-
|
|
197
|
-
|
|
254
|
+
// Convert the errorValue into an errorString
|
|
255
|
+
entry.accessory.errorString = new Error( constants.errorString( error ) );
|
|
256
|
+
|
|
257
|
+
// This does not work - Nothing happens to HomeKit !
|
|
258
|
+
// queue.log.warn( `START processHighPrioritySetQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue} errorString: ${ entry.accessory.errorString }`);
|
|
259
|
+
// entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( entry.accessory.errorString );
|
|
260
|
+
// queue.log.warn( `END processHighPrioritySetQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue} errorString: ${ entry.accessory.errorString }`);
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
} else
|
|
264
|
+
{
|
|
265
|
+
// Increment the errorCount/currentRetryCount
|
|
266
|
+
queue.errorCountSinceLastGoodTransaction++;
|
|
267
|
+
|
|
268
|
+
// Set failed. We need to keep trying
|
|
269
|
+
queue.highPriorityQueue.push( entry );
|
|
270
|
+
|
|
271
|
+
}
|
|
198
272
|
|
|
199
273
|
entry.accessory.queue.pauseQueue( entry.accessory.queue );
|
|
200
274
|
}
|
|
@@ -204,7 +278,7 @@ class Cmd4PriorityPollingQueue
|
|
|
204
278
|
// created.
|
|
205
279
|
|
|
206
280
|
// Note 2.
|
|
207
|
-
// We cannot release the queue for further processing as the
|
|
281
|
+
// We cannot release the queue for further processing as the
|
|
208
282
|
// statechangeResponseTime has not completed. This must be
|
|
209
283
|
// done first or any next "Get" or "Set" would interfere
|
|
210
284
|
// with the device
|
|
@@ -222,28 +296,50 @@ class Cmd4PriorityPollingQueue
|
|
|
222
296
|
{
|
|
223
297
|
let queue = entry.accessory.queue;
|
|
224
298
|
|
|
299
|
+
// Save the error code - Pass or fail
|
|
300
|
+
entry.accessory.errorValue = error;
|
|
301
|
+
|
|
225
302
|
// Nothing special was done for casing on errors, so omit it.
|
|
226
303
|
if ( error == 0 )
|
|
227
304
|
{
|
|
228
|
-
|
|
305
|
+
// Save the new returned value
|
|
306
|
+
entry.accessory.cmd4Storage.setStoredValueForIndex( entry.accTypeEnumIndex, properValue );
|
|
307
|
+
|
|
308
|
+
// hmmm if ( entry.queueGetIsUpdate == true )
|
|
229
309
|
entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( properValue );
|
|
230
310
|
|
|
231
311
|
// A good anything, updates the lastGoodTransactionTime
|
|
232
312
|
queue.lastGoodTransactionTime = Date.now( );
|
|
233
313
|
queue.errorCountSinceLastGoodTransaction = 0;
|
|
234
314
|
|
|
235
|
-
} else // getValue failed
|
|
315
|
+
} else // highPriority getValue failed
|
|
236
316
|
{
|
|
237
|
-
// High Priority Get failed. We need to keep trying (WoRm queue only )
|
|
238
|
-
if ( queue.queueType == constants.QUEUETYPE_WORM ||
|
|
239
|
-
queue.queueType == constants.QUEUETYPE_WORM2
|
|
240
|
-
)
|
|
241
|
-
queue.highPriorityQueue.push( entry );
|
|
242
317
|
|
|
243
|
-
queue.errorCountSinceLastGoodTransaction
|
|
244
|
-
|
|
245
|
-
if (
|
|
246
|
-
|
|
318
|
+
let currentRetryCount = queue.errorCountSinceLastGoodTransaction;
|
|
319
|
+
|
|
320
|
+
if ( currentRetryCount >= queue.queueRetryCount )
|
|
321
|
+
{
|
|
322
|
+
if ( queue.echoRetryErrors( currentRetryCount ) )
|
|
323
|
+
queue.log.warn( `*${ currentRetryCount + 1}* error(s) were encountered for "${ entry.accessory.displayName }" getValue. Last error found Getting: "${ entry.characteristicString}". Perhaps you should run in debug mode to find out what the problem might be.` );
|
|
324
|
+
|
|
325
|
+
// Convert the errorValue into an errorString
|
|
326
|
+
entry.accessory.errorString = new Error( constants.errorString( error ) );
|
|
327
|
+
|
|
328
|
+
// This does not work - Nothing happens to HomeKit !
|
|
329
|
+
// queue.log.warn( `START processHighPriorityGetQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue} errorString: ${ entry.accessory.errorString }`);
|
|
330
|
+
// entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( entry.accessory.errorString );
|
|
331
|
+
// queue.log.warn( `END processHighPriorityGetQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue} errorString: ${ entry.accessory.errorString }`);
|
|
332
|
+
|
|
333
|
+
} else
|
|
334
|
+
{
|
|
335
|
+
// Increment the errorCount/currentRetryCount
|
|
336
|
+
queue.errorCountSinceLastGoodTransaction++;
|
|
337
|
+
|
|
338
|
+
// High Priority Get failed. We keep retrying until the mod of
|
|
339
|
+
// queueRetryCount reaches zero, which is WoRm only as it has more than 1
|
|
340
|
+
// default retry count.
|
|
341
|
+
queue.highPriorityQueue.push( entry );
|
|
342
|
+
}
|
|
247
343
|
|
|
248
344
|
entry.accessory.queue.pauseQueue( entry.accessory.queue );
|
|
249
345
|
}
|
|
@@ -254,6 +350,7 @@ class Cmd4PriorityPollingQueue
|
|
|
254
350
|
});
|
|
255
351
|
}
|
|
256
352
|
|
|
353
|
+
// This is called from polling
|
|
257
354
|
processEntryFromLowPriorityQueue( entry )
|
|
258
355
|
{
|
|
259
356
|
if ( settings.cmd4Dbg ) this.log.debug( `Processing low priority queue entry: ${ entry.accTypeEnumIndex }` );
|
|
@@ -268,20 +365,40 @@ class Cmd4PriorityPollingQueue
|
|
|
268
365
|
// For the next one
|
|
269
366
|
queue.inProgressGets --;
|
|
270
367
|
|
|
368
|
+
// Save the error code - Pass or fail
|
|
369
|
+
entry.accessory.errorValue = error;
|
|
370
|
+
|
|
271
371
|
// Nothing special was done for casing on errors, so omit it.
|
|
272
372
|
if ( error == 0 )
|
|
273
373
|
{
|
|
374
|
+
// Save the new value
|
|
375
|
+
entry.accessory.cmd4Storage.setStoredValueForIndex( entry.accTypeEnumIndex, properValue );
|
|
376
|
+
|
|
377
|
+
if ( settings.cmd4Dbg ) entry.accessory.log.debug( `processEntryFromLowPriorityQueue calling updateValue properValue: ${ properValue }`);
|
|
378
|
+
|
|
379
|
+
// Update the new value in homebridge
|
|
274
380
|
entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( properValue );
|
|
275
381
|
|
|
276
382
|
// A good anything, updates the lastGoodTransactionTime
|
|
277
383
|
queue.lastGoodTransactionTime = Date.now( );
|
|
278
384
|
queue.errorCountSinceLastGoodTransaction = 0;
|
|
279
385
|
|
|
280
|
-
} else {
|
|
386
|
+
} else { // LowPriority getValue failed
|
|
387
|
+
queue.errorCountSinceLastGoodTransaction++;
|
|
388
|
+
|
|
389
|
+
// Convert the errorValue into an errorString
|
|
390
|
+
entry.accessory.errorString = new Error( constants.errorString( error ));
|
|
391
|
+
|
|
392
|
+
// This does not work - Nothing happens to HomeKit !
|
|
393
|
+
// Call updateValue with new Error so device will become unavailable
|
|
394
|
+
// queue.log.warn( `START processEntryFromLowPriorityQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue } errorString: ${ entry.accessory.errorString }`);
|
|
395
|
+
// entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( entry.accessory.errorString );
|
|
396
|
+
// queue.log.warn( `END processEntryFromLowPriorityQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue } errorString: ${ entry.accessory.errorString }`);
|
|
397
|
+
|
|
281
398
|
queue.pauseQueue( entry.accessory.queue );
|
|
282
399
|
}
|
|
283
400
|
|
|
284
|
-
// Now that this one has been processed, schedule it again
|
|
401
|
+
// Now that this one has been processed, schedule it again for next time
|
|
285
402
|
queue.scheduleLowPriorityEntry( entry )
|
|
286
403
|
|
|
287
404
|
});
|
|
@@ -477,7 +594,7 @@ class Cmd4PriorityPollingQueue
|
|
|
477
594
|
//
|
|
478
595
|
// - Where he value in <> is an one of CMD4_ACC_TYPE_ENUM
|
|
479
596
|
// ***********************************************
|
|
480
|
-
qSetValue( accessory, accTypeEnumIndex, characteristicString, timeout, value,
|
|
597
|
+
qSetValue( accessory, accTypeEnumIndex, characteristicString, timeout, value, queueCallback )
|
|
481
598
|
{
|
|
482
599
|
let self = accessory;
|
|
483
600
|
let queue = accessory.queue;
|
|
@@ -515,17 +632,17 @@ class Cmd4PriorityPollingQueue
|
|
|
515
632
|
{
|
|
516
633
|
if ( queue.echoE ) self.log.error( chalk.red( `setValue ${ characteristicString } function failed for ${ self.displayName } cmd: ${ cmd } Failed. Error: ${ code } ${ constants.DBUSY }` ) );
|
|
517
634
|
|
|
518
|
-
|
|
635
|
+
queueCallback( constants.ERROR_TIMER_EXPIRED );
|
|
519
636
|
|
|
520
637
|
return;
|
|
521
638
|
}
|
|
522
639
|
|
|
523
|
-
|
|
640
|
+
queueCallback( code );
|
|
524
641
|
|
|
525
642
|
return;
|
|
526
643
|
}
|
|
527
644
|
|
|
528
|
-
|
|
645
|
+
queueCallback( code );
|
|
529
646
|
|
|
530
647
|
});
|
|
531
648
|
}
|
|
@@ -537,13 +654,21 @@ class Cmd4PriorityPollingQueue
|
|
|
537
654
|
{
|
|
538
655
|
// "WoRm", No matter what, only one "Set" allowed
|
|
539
656
|
if ( queue.inProgressSets > 0 )
|
|
657
|
+
{
|
|
658
|
+
// if ( settings.cmd4Dbg ) queue.log.debug(`processWormQueue queue.inProgressSets > 0 : ${queue.inProgressSets}`);
|
|
659
|
+
|
|
540
660
|
// We are *NOT* processing the low prioirity queue entry
|
|
541
661
|
return false;
|
|
662
|
+
}
|
|
542
663
|
|
|
543
664
|
// It is not a good time to do a anything, so skip it
|
|
544
665
|
if ( queue.lastGoodTransactionTime == 0 )
|
|
666
|
+
{
|
|
667
|
+
// if ( settings.cmd4Dbg ) queue.log.debug(`processWormQueue queue.lastGoodTransactionTime == 0`);
|
|
668
|
+
|
|
545
669
|
// We are *NOT* processing the low prioirity queue entry
|
|
546
670
|
return false;
|
|
671
|
+
}
|
|
547
672
|
|
|
548
673
|
if ( queue.highPriorityQueue.length > 0 )
|
|
549
674
|
{
|
|
@@ -556,9 +681,13 @@ class Cmd4PriorityPollingQueue
|
|
|
556
681
|
// cannot be run with an entry already in progress.
|
|
557
682
|
if ( nextEntry.accessory.queue.inProgressSets > 0 ||
|
|
558
683
|
nextEntry.accessory.queue.inProgressGets > 0 )
|
|
684
|
+
{
|
|
559
685
|
// Return as queue is busy.
|
|
560
686
|
// Return false as we are *NOT* processing the low prioirity queue entry
|
|
687
|
+
// if ( settings.cmd4Dbg ) queue.log.debug(`processWormQueue queue.inProgressSets> 0 ${ nextEntry.accessory.queue.inProgressSets } ${ nextEntry.accessory.queue.inProgressGets }`);
|
|
688
|
+
|
|
561
689
|
return false;
|
|
690
|
+
}
|
|
562
691
|
|
|
563
692
|
queue.processHighPrioritySetQueue( queue.highPriorityQueue.shift( ) );
|
|
564
693
|
|
|
@@ -695,38 +824,44 @@ class Cmd4PriorityPollingQueue
|
|
|
695
824
|
if ( lastTransactionType == LOW_PRIORITY_GET &&
|
|
696
825
|
lowPriorityEntry != null &&
|
|
697
826
|
queue.queueStarted == true )
|
|
827
|
+
{
|
|
698
828
|
queue.processEntryFromLowPriorityQueue( lowPriorityEntry );
|
|
829
|
+
}
|
|
699
830
|
|
|
700
831
|
if ( queue.highPriorityQueue.length > 0 )
|
|
701
832
|
{
|
|
702
833
|
let nextEntry = queue.highPriorityQueue[ 0 ];
|
|
703
834
|
|
|
704
835
|
if ( nextEntry.isSet == true )
|
|
836
|
+
{
|
|
705
837
|
|
|
706
838
|
queue.processHighPrioritySetQueue( queue.highPriorityQueue.shift( ) );
|
|
839
|
+
}
|
|
707
840
|
else
|
|
841
|
+
{
|
|
708
842
|
queue.processHighPriorityGetQueue( queue.highPriorityQueue.shift( ) );
|
|
843
|
+
}
|
|
709
844
|
}
|
|
710
845
|
}
|
|
711
846
|
|
|
712
847
|
scheduleLowPriorityEntry( entry )
|
|
713
848
|
{
|
|
714
|
-
let
|
|
849
|
+
let accessory = entry.accessory;
|
|
715
850
|
let queue = entry.accessory.queue;
|
|
716
851
|
|
|
717
|
-
if ( settings.cmd4Dbg )
|
|
852
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( `Scheduling Poll of index: ${ entry.accTypeEnumIndex } characteristic: ${ entry.characteristicString } for: ${ accessory.displayName } timeout: ${ entry.timeout } interval: ${ entry.interval }` );
|
|
718
853
|
|
|
719
854
|
// Clear polling
|
|
720
855
|
if ( queue.listOfRunningPolls &&
|
|
721
|
-
queue.listOfRunningPolls[
|
|
722
|
-
clearTimeout( queue.listOfRunningPolls[
|
|
856
|
+
queue.listOfRunningPolls[ accessory.displayName + entry.accTypeEnumIndex ] == undefined )
|
|
857
|
+
clearTimeout( queue.listOfRunningPolls[ accessory.displayName + entry.accTypeEnumIndex ] );
|
|
723
858
|
|
|
724
|
-
queue.listOfRunningPolls[
|
|
859
|
+
queue.listOfRunningPolls[ accessory.displayName + entry.accTypeEnumIndex ] = setTimeout( ( ) =>
|
|
725
860
|
{
|
|
726
861
|
// If the queue was busy/not available, schedule the entry at a later time
|
|
727
862
|
if ( queue.processQueueFunc( LOW_PRIORITY_GET, queue, entry ) == false )
|
|
728
863
|
{
|
|
729
|
-
if ( settings.cmd4Dbg )
|
|
864
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( `processsQueue returned false` );
|
|
730
865
|
|
|
731
866
|
queue.scheduleLowPriorityEntry( entry );
|
|
732
867
|
}
|
|
@@ -803,12 +938,17 @@ class Cmd4PriorityPollingQueue
|
|
|
803
938
|
setTimeout( ( ) =>
|
|
804
939
|
{
|
|
805
940
|
if ( entryIndex == 0 && settings.cmd4Dbg )
|
|
941
|
+
{
|
|
806
942
|
if ( queue.queueType == constants.QUEUETYPE_WORM ||
|
|
807
943
|
queue.queueType == constants.QUEUETYPE_WORM2
|
|
808
944
|
)
|
|
945
|
+
{
|
|
809
946
|
entry.accessory.log.debug( `Started staggered kick off of ${ queue.lowPriorityQueue.length } polled characteristics for queue: "${ entry.accessory.queue.queueName }"` );
|
|
810
|
-
else
|
|
947
|
+
} else
|
|
948
|
+
{
|
|
811
949
|
entry.accessory.log.debug( `Started staggered kick off of ${ queue.lowPriorityQueue.length } polled characteristics for "${ entry.accessory.displayName }"` );
|
|
950
|
+
}
|
|
951
|
+
}
|
|
812
952
|
|
|
813
953
|
if ( settings.cmd4Dbg ) entry.accessory.log.debug( `Kicking off polling for: ${ entry.accessory.displayName } ${ entry.characteristicString } interval:${ entry.interval }, staggered:${ staggeredDelays[ staggeredDelayIndex ] }` );
|
|
814
954
|
|
|
@@ -817,12 +957,18 @@ class Cmd4PriorityPollingQueue
|
|
|
817
957
|
if ( entryIndex == queue.lowPriorityQueue.length -1 )
|
|
818
958
|
{
|
|
819
959
|
if ( settings.cmd4Dbg )
|
|
960
|
+
{
|
|
820
961
|
if ( queue.queueType == constants.QUEUETYPE_WORM ||
|
|
821
962
|
queue.queueType == constants.QUEUETYPE_WORM2
|
|
822
963
|
)
|
|
964
|
+
{
|
|
823
965
|
entry.accessory.log.debug( `All characteristics are now being polled for queue: "${ queue.queueName }"` );
|
|
966
|
+
}
|
|
824
967
|
else
|
|
968
|
+
{
|
|
825
969
|
entry.accessory.log.debug( `All characteristics are now being polled for "${ entry.accessory.displayName }"` );
|
|
970
|
+
}
|
|
971
|
+
}
|
|
826
972
|
allDoneCallback( allDoneCount );
|
|
827
973
|
}
|
|
828
974
|
|
|
@@ -901,15 +1047,15 @@ var queueExists = function( queueName )
|
|
|
901
1047
|
return settings.listOfCreatedPriorityQueues[ queueName ];
|
|
902
1048
|
}
|
|
903
1049
|
|
|
904
|
-
var addQueue = function( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE )
|
|
1050
|
+
var addQueue = function( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE, queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT )
|
|
905
1051
|
{
|
|
906
1052
|
let queue = queueExists( queueName );
|
|
907
1053
|
if ( queue != undefined )
|
|
908
1054
|
return queue;
|
|
909
1055
|
|
|
910
|
-
log.debug( `Creating new Priority Polled Queue "${ queueName }" with QueueType of: "${ queueType }"` );
|
|
1056
|
+
log.debug( `Creating new Priority Polled Queue "${ queueName }" with QueueType of: "${ queueType }" retryCount: ${queueRetryCount}` );
|
|
911
1057
|
|
|
912
|
-
queue = new Cmd4PriorityPollingQueue( log, queueName, queueType );
|
|
1058
|
+
queue = new Cmd4PriorityPollingQueue( log, queueName, queueType, queueRetryCount );
|
|
913
1059
|
settings.listOfCreatedPriorityQueues[ queueName ] = queue;
|
|
914
1060
|
|
|
915
1061
|
return queue;
|
|
@@ -927,6 +1073,7 @@ var parseAddQueueTypes = function ( log, entrys )
|
|
|
927
1073
|
{
|
|
928
1074
|
let queueName = null;
|
|
929
1075
|
let queueType = constants.DEFAULT_QUEUE_TYPE;
|
|
1076
|
+
let queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT;
|
|
930
1077
|
|
|
931
1078
|
for ( let key in entry )
|
|
932
1079
|
{
|
|
@@ -950,25 +1097,33 @@ var parseAddQueueTypes = function ( log, entrys )
|
|
|
950
1097
|
|
|
951
1098
|
break;
|
|
952
1099
|
case constants.QUEUETYPE:
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
value != constants.QUEUETYPE_SEQUENTIAL )
|
|
1100
|
+
// Set the default Queue Retry Count based on QueueType
|
|
1101
|
+
switch ( value )
|
|
956
1102
|
{
|
|
957
|
-
|
|
1103
|
+
case constants.QUEUETYPE_WORM:
|
|
1104
|
+
queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT;
|
|
1105
|
+
queueType = value;
|
|
1106
|
+
break;
|
|
1107
|
+
case constants.QUEUETYPE_WORM2:
|
|
1108
|
+
queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT;
|
|
1109
|
+
queueType = value;
|
|
1110
|
+
break;
|
|
1111
|
+
case constants.QUEUETYPE_SEQUENTIAL:
|
|
1112
|
+
queueRetryCount = constants.DEFAULT_STANDARD_QUEUE_RETRY_COUNT;
|
|
1113
|
+
queueType = value;
|
|
1114
|
+
break;
|
|
1115
|
+
case constants.QUEUETYPE_STANDARD:
|
|
1116
|
+
queueRetryCount = constants.DEFAULT_STANDARD_QUEUE_RETRY_COUNT;
|
|
1117
|
+
queueType = value;
|
|
1118
|
+
break;
|
|
1119
|
+
default:
|
|
1120
|
+
throw new Error( `QueueType: ${ entry.queueType } is not valid at index: ${ entryIndex }. Expected: ${ constants.QUEUETYPE_WORM }, ${ constants.QUEUETYPE_WORM2 } or ${ constants.QUEUETYPE_SEQUENTIAL }` );
|
|
958
1121
|
}
|
|
959
1122
|
|
|
960
|
-
queueType = value;
|
|
961
|
-
|
|
962
1123
|
break;
|
|
963
|
-
case
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
// Never put into production
|
|
968
|
-
log.warn( `Warning: ${ key } has been deprecated. It was never really used anyway.` );
|
|
969
|
-
log.warn( `To remove this message, just remove ${ key } from your config.json` );
|
|
970
|
-
|
|
971
|
-
break;
|
|
1124
|
+
case constants.QUEUE_RETRIES:
|
|
1125
|
+
queueRetryCount = value;
|
|
1126
|
+
break;
|
|
972
1127
|
default:
|
|
973
1128
|
throw new Error( `Unknown Queue option"${ key } not provided at index ${ entryIndex }` );
|
|
974
1129
|
}
|
|
@@ -978,8 +1133,9 @@ var parseAddQueueTypes = function ( log, entrys )
|
|
|
978
1133
|
if ( queueName == null )
|
|
979
1134
|
throw new Error( `"${ constants.QUEUE }" not provided at index ${ entryIndex }` );
|
|
980
1135
|
|
|
981
|
-
if ( settings.cmd4Dbg ) log.debug( `calling addQueue: ${ queueName } type: ${ queueType }` );
|
|
982
|
-
|
|
1136
|
+
if ( settings.cmd4Dbg ) log.debug( `calling addQueue: ${ queueName } type: ${ queueType } retryCount: ${ queueRetryCount }` );
|
|
1137
|
+
|
|
1138
|
+
addQueue( log, queueName, queueType, queueRetryCount );
|
|
983
1139
|
} );
|
|
984
1140
|
}
|
|
985
1141
|
|