homebridge-cmd4 6.3.0-beta.1 → 7.0.0

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.
@@ -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
- this.echoE = true;
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
- prioritySetValue( accTypeEnumIndex, characteristicString, timeout, stateChangeResponseTime, value, callback )
77
+ echoRetryErrors( currentRetryCount )
78
+ {
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 )
73
94
  {
74
- let self = this;
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
- self.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, value );
78
- callback( 0 );
100
+ // this.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, value );
79
101
 
80
- let newEntry = { [ constants.IS_SET_lv ]: true, [ constants.ACCESSORY_lv ]: self, [ 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 ]: callback, [ constants.VALUE_lv ]: value };
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
+ }
111
+
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 ( self.queue.highPriorityQueue.length == 0 )
115
+ if ( this.queue.highPriorityQueue.length == 0 )
84
116
  {
85
117
  // No entries, then it goes on top
86
- self.queue.highPriorityQueue.push( newEntry );
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 = self.queue.highPriorityQueue.findIndex( ( entry ) => entry.accessory.uuid == self.uuid && entry.isSet == true && entry.accTypeEnumIndex == accTypeEnumIndex );
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 = self.queue.highPriorityQueue.findIndex( ( entry ) => entry.isSet == false );
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
- self.queue.highPriorityQueue.push( newEntry );
134
+ this.queue.highPriorityQueue.push( newEntry );
103
135
 
104
136
  } else
105
137
  {
106
138
  // Insert before the first "Get" entry
107
- self.queue.highPriorityQueue.splice( getIndex, 0, newEntry );
139
+ this.queue.highPriorityQueue.splice( getIndex, 0, newEntry );
108
140
  }
109
141
  } else
110
142
  {
111
- self.queue.highPriorityQueue[ index ] = newEntry;
143
+ this.queue.highPriorityQueue[ index ] = newEntry;
112
144
  }
113
145
  }
114
- self.queue.processQueueFunc( HIGH_PRIORITY_SET, self.queue );
146
+ this.queue.processQueueFunc( HIGH_PRIORITY_SET, this.queue );
115
147
  }
116
148
 
117
- priorityGetValue( accTypeEnumIndex, characteristicString, timeout, callback )
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
- let self = this;
156
+ // this is Accessory
157
+
158
+ // if ( settings.cmd4Dbg ) this.log.debug(`priorityGetValue for ${ this.displayName }, asked to Get: ${ characteristicString }`);
159
+
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 );
120
168
 
121
- // return the cached value
122
- let storedValue = self.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex );
123
- callback( 0, storedValue );
169
+ // if ( settings.cmd4Dbg ) this.log.debug(`priorityGetValue for ${ this.displayName }, homebridgeCallback returning storedValue: ${ storedValue }`);
170
+ homebridgeCallback( 0, storedValue );
171
+ }
124
172
 
125
- if ( self.queue.queueType != constants.QUEUETYPE_WORM2 )
173
+ if ( this.queue.queueType != constants.QUEUETYPE_WORM2 )
126
174
  {
127
175
  // When the value is returned, it will update homebridge
128
- self.queue.highPriorityQueue.push( { [ constants.IS_SET_lv ]: false, [ constants.QUEUE_GET_IS_UPDATE_lv ]: true, [ constants.ACCESSORY_lv ]: self, [ 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 ]: callback } );
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
- self.queue.processQueueFunc( HIGH_PRIORITY_GET, self.queue );
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,8 +197,14 @@ 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
  {
@@ -183,18 +238,37 @@ class Cmd4PriorityPollingQueue
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
- // Set failed. We need to keep trying
191
- queue.highPriorityQueue.push( entry );
244
+ let currentRetryCount = queue.errorCountSinceLastGoodTransaction;
192
245
 
193
- queue.errorCountSinceLastGoodTransaction++;
194
- let count = queue.errorCountSinceLastGoodTransaction;
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
+ }
253
+
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 }`);
195
261
 
196
- if ( count != 0 && count % 50 == 0 )
197
- queue.log.warn( `More than *${ count }* errors were encountered in a row for "${ entry.accessory.displayName }" setValue. Last error found Setting: "${ entry.characteristicString}". Perhaps you should run in debug mode to find out what the problem might be.` );
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
- if ( entry.queueGetIsUpdate == true )
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
- let count = queue.errorCountSinceLastGoodTransaction;
245
- if ( count != 0 && count % 50 == 0 )
246
- queue.log.warn( `More than *${ count }* errors were encountered in a row 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.` );
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,39 @@ 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
+ // Update the new value in homebridge
378
+ entry.accessory.log.warn( `processEntryFromLowPriorityQueue calling updateValue properValue: ${ properValue }`);
274
379
  entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( properValue );
275
380
 
276
381
  // A good anything, updates the lastGoodTransactionTime
277
382
  queue.lastGoodTransactionTime = Date.now( );
278
383
  queue.errorCountSinceLastGoodTransaction = 0;
279
384
 
280
- } else {
385
+ } else { // LowPriority getValue failed
386
+ queue.errorCountSinceLastGoodTransaction++;
387
+
388
+ // Convert the errorValue into an errorString
389
+ entry.accessory.errorString = new Error( constants.errorString( error ));
390
+
391
+ // This does not work - Nothing happens to HomeKit !
392
+ // Call updateValue with new Error so device will become unavailable
393
+ // queue.log.warn( `START processEntryFromLowPriorityQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue } errorString: ${ entry.accessory.errorString }`);
394
+ // entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( entry.accessory.errorString );
395
+ // queue.log.warn( `END processEntryFromLowPriorityQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue } errorString: ${ entry.accessory.errorString }`);
396
+
281
397
  queue.pauseQueue( entry.accessory.queue );
282
398
  }
283
399
 
284
- // Now that this one has been processed, schedule it again.
400
+ // Now that this one has been processed, schedule it again for next time
285
401
  queue.scheduleLowPriorityEntry( entry )
286
402
 
287
403
  });
@@ -477,7 +593,7 @@ class Cmd4PriorityPollingQueue
477
593
  //
478
594
  // - Where he value in <> is an one of CMD4_ACC_TYPE_ENUM
479
595
  // ***********************************************
480
- qSetValue( accessory, accTypeEnumIndex, characteristicString, timeout, value, callback )
596
+ qSetValue( accessory, accTypeEnumIndex, characteristicString, timeout, value, queueCallback )
481
597
  {
482
598
  let self = accessory;
483
599
  let queue = accessory.queue;
@@ -515,17 +631,17 @@ class Cmd4PriorityPollingQueue
515
631
  {
516
632
  if ( queue.echoE ) self.log.error( chalk.red( `setValue ${ characteristicString } function failed for ${ self.displayName } cmd: ${ cmd } Failed. Error: ${ code } ${ constants.DBUSY }` ) );
517
633
 
518
- callback( constants.ERROR_TIMER_EXPIRED );
634
+ queueCallback( constants.ERROR_TIMER_EXPIRED );
519
635
 
520
636
  return;
521
637
  }
522
638
 
523
- callback( code );
639
+ queueCallback( code );
524
640
 
525
641
  return;
526
642
  }
527
643
 
528
- callback( code );
644
+ queueCallback( code );
529
645
 
530
646
  });
531
647
  }
@@ -537,13 +653,21 @@ class Cmd4PriorityPollingQueue
537
653
  {
538
654
  // "WoRm", No matter what, only one "Set" allowed
539
655
  if ( queue.inProgressSets > 0 )
656
+ {
657
+ // if ( settings.cmd4Dbg ) queue.log.debug(`processWormQueue queue.inProgressSets > 0 : ${queue.inProgressSets}`);
658
+
540
659
  // We are *NOT* processing the low prioirity queue entry
541
660
  return false;
661
+ }
542
662
 
543
663
  // It is not a good time to do a anything, so skip it
544
664
  if ( queue.lastGoodTransactionTime == 0 )
665
+ {
666
+ // if ( settings.cmd4Dbg ) queue.log.debug(`processWormQueue queue.lastGoodTransactionTime == 0`);
667
+
545
668
  // We are *NOT* processing the low prioirity queue entry
546
669
  return false;
670
+ }
547
671
 
548
672
  if ( queue.highPriorityQueue.length > 0 )
549
673
  {
@@ -556,9 +680,13 @@ class Cmd4PriorityPollingQueue
556
680
  // cannot be run with an entry already in progress.
557
681
  if ( nextEntry.accessory.queue.inProgressSets > 0 ||
558
682
  nextEntry.accessory.queue.inProgressGets > 0 )
683
+ {
559
684
  // Return as queue is busy.
560
685
  // Return false as we are *NOT* processing the low prioirity queue entry
686
+ // if ( settings.cmd4Dbg ) queue.log.debug(`processWormQueue queue.inProgressSets> 0 ${ nextEntry.accessory.queue.inProgressSets } ${ nextEntry.accessory.queue.inProgressGets }`);
687
+
561
688
  return false;
689
+ }
562
690
 
563
691
  queue.processHighPrioritySetQueue( queue.highPriorityQueue.shift( ) );
564
692
 
@@ -695,7 +823,9 @@ class Cmd4PriorityPollingQueue
695
823
  if ( lastTransactionType == LOW_PRIORITY_GET &&
696
824
  lowPriorityEntry != null &&
697
825
  queue.queueStarted == true )
826
+ {
698
827
  queue.processEntryFromLowPriorityQueue( lowPriorityEntry );
828
+ }
699
829
 
700
830
  if ( queue.highPriorityQueue.length > 0 )
701
831
  {
@@ -711,22 +841,22 @@ class Cmd4PriorityPollingQueue
711
841
 
712
842
  scheduleLowPriorityEntry( entry )
713
843
  {
714
- let self = entry.accessory;
844
+ let accessory = entry.accessory;
715
845
  let queue = entry.accessory.queue;
716
846
 
717
- if ( settings.cmd4Dbg ) self.log.debug( `Scheduling Poll of index: ${ entry.accTypeEnumIndex } characteristic: ${ entry.characteristicString } for: ${ self.displayName } timeout: ${ entry.timeout } interval: ${ entry.interval }` );
847
+ 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
848
 
719
849
  // Clear polling
720
850
  if ( queue.listOfRunningPolls &&
721
- queue.listOfRunningPolls[ self.displayName + entry.accTypeEnumIndex ] == undefined )
722
- clearTimeout( queue.listOfRunningPolls[ self.displayName + entry.accTypeEnumIndex ] );
851
+ queue.listOfRunningPolls[ accessory.displayName + entry.accTypeEnumIndex ] == undefined )
852
+ clearTimeout( queue.listOfRunningPolls[ accessory.displayName + entry.accTypeEnumIndex ] );
723
853
 
724
- queue.listOfRunningPolls[ self.displayName + entry.accTypeEnumIndex ] = setTimeout( ( ) =>
854
+ queue.listOfRunningPolls[ accessory.displayName + entry.accTypeEnumIndex ] = setTimeout( ( ) =>
725
855
  {
726
856
  // If the queue was busy/not available, schedule the entry at a later time
727
857
  if ( queue.processQueueFunc( LOW_PRIORITY_GET, queue, entry ) == false )
728
858
  {
729
- if ( settings.cmd4Dbg ) self.log.debug( `processsQueue returned false` );
859
+ if ( settings.cmd4Dbg ) accessory.log.debug( `processsQueue returned false` );
730
860
 
731
861
  queue.scheduleLowPriorityEntry( entry );
732
862
  }
@@ -803,12 +933,17 @@ class Cmd4PriorityPollingQueue
803
933
  setTimeout( ( ) =>
804
934
  {
805
935
  if ( entryIndex == 0 && settings.cmd4Dbg )
936
+ {
806
937
  if ( queue.queueType == constants.QUEUETYPE_WORM ||
807
938
  queue.queueType == constants.QUEUETYPE_WORM2
808
939
  )
940
+ {
809
941
  entry.accessory.log.debug( `Started staggered kick off of ${ queue.lowPriorityQueue.length } polled characteristics for queue: "${ entry.accessory.queue.queueName }"` );
810
- else
942
+ } else
943
+ {
811
944
  entry.accessory.log.debug( `Started staggered kick off of ${ queue.lowPriorityQueue.length } polled characteristics for "${ entry.accessory.displayName }"` );
945
+ }
946
+ }
812
947
 
813
948
  if ( settings.cmd4Dbg ) entry.accessory.log.debug( `Kicking off polling for: ${ entry.accessory.displayName } ${ entry.characteristicString } interval:${ entry.interval }, staggered:${ staggeredDelays[ staggeredDelayIndex ] }` );
814
949
 
@@ -817,12 +952,18 @@ class Cmd4PriorityPollingQueue
817
952
  if ( entryIndex == queue.lowPriorityQueue.length -1 )
818
953
  {
819
954
  if ( settings.cmd4Dbg )
955
+ {
820
956
  if ( queue.queueType == constants.QUEUETYPE_WORM ||
821
957
  queue.queueType == constants.QUEUETYPE_WORM2
822
958
  )
959
+ {
823
960
  entry.accessory.log.debug( `All characteristics are now being polled for queue: "${ queue.queueName }"` );
961
+ }
824
962
  else
963
+ {
825
964
  entry.accessory.log.debug( `All characteristics are now being polled for "${ entry.accessory.displayName }"` );
965
+ }
966
+ }
826
967
  allDoneCallback( allDoneCount );
827
968
  }
828
969
 
@@ -901,15 +1042,15 @@ var queueExists = function( queueName )
901
1042
  return settings.listOfCreatedPriorityQueues[ queueName ];
902
1043
  }
903
1044
 
904
- var addQueue = function( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE )
1045
+ var addQueue = function( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE, queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT )
905
1046
  {
906
1047
  let queue = queueExists( queueName );
907
1048
  if ( queue != undefined )
908
1049
  return queue;
909
1050
 
910
- log.debug( `Creating new Priority Polled Queue "${ queueName }" with QueueType of: "${ queueType }"` );
1051
+ log.debug( `Creating new Priority Polled Queue "${ queueName }" with QueueType of: "${ queueType }" retryCount: ${queueRetryCount}` );
911
1052
 
912
- queue = new Cmd4PriorityPollingQueue( log, queueName, queueType );
1053
+ queue = new Cmd4PriorityPollingQueue( log, queueName, queueType, queueRetryCount );
913
1054
  settings.listOfCreatedPriorityQueues[ queueName ] = queue;
914
1055
 
915
1056
  return queue;
@@ -927,6 +1068,7 @@ var parseAddQueueTypes = function ( log, entrys )
927
1068
  {
928
1069
  let queueName = null;
929
1070
  let queueType = constants.DEFAULT_QUEUE_TYPE;
1071
+ let queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT;
930
1072
 
931
1073
  for ( let key in entry )
932
1074
  {
@@ -950,25 +1092,33 @@ var parseAddQueueTypes = function ( log, entrys )
950
1092
 
951
1093
  break;
952
1094
  case constants.QUEUETYPE:
953
- if ( value != constants.QUEUETYPE_WORM &&
954
- value != constants.QUEUETYPE_WORM2 &&
955
- value != constants.QUEUETYPE_SEQUENTIAL )
1095
+ // Set the default Queue Retry Count based on QueueType
1096
+ switch ( value )
956
1097
  {
957
- throw new Error( `QueueType: ${ entry.queueType } is not valid at index: ${ entryIndex }. Expected: ${ constants.QUEUETYPE_WORM }, ${ constants.QUEUETYPE_WORM2 } or ${ constants.QUEUETYPE_SEQUENTIAL }` );
1098
+ case constants.QUEUETYPE_WORM:
1099
+ queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT;
1100
+ queueType = value;
1101
+ break;
1102
+ case constants.QUEUETYPE_WORM2:
1103
+ queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT;
1104
+ queueType = value;
1105
+ break;
1106
+ case constants.QUEUETYPE_SEQUENTIAL:
1107
+ queueRetryCount = constants.DEFAULT_STANDARD_QUEUE_RETRY_COUNT;
1108
+ queueType = value;
1109
+ break;
1110
+ case constants.QUEUETYPE_STANDARD:
1111
+ queueRetryCount = constants.DEFAULT_STANDARD_QUEUE_RETRY_COUNT;
1112
+ queueType = value;
1113
+ break;
1114
+ default:
1115
+ throw new Error( `QueueType: ${ entry.queueType } is not valid at index: ${ entryIndex }. Expected: ${ constants.QUEUETYPE_WORM }, ${ constants.QUEUETYPE_WORM2 } or ${ constants.QUEUETYPE_SEQUENTIAL }` );
958
1116
  }
959
1117
 
960
- queueType = value;
961
-
962
1118
  break;
963
- case "QueueInterval":
964
- case "QueueMsg":
965
- case "QueueStatMsgInterval":
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;
1119
+ case constants.QUEUE_RETRIES:
1120
+ queueRetryCount = value;
1121
+ break;
972
1122
  default:
973
1123
  throw new Error( `Unknown Queue option"${ key } not provided at index ${ entryIndex }` );
974
1124
  }
@@ -978,8 +1128,9 @@ var parseAddQueueTypes = function ( log, entrys )
978
1128
  if ( queueName == null )
979
1129
  throw new Error( `"${ constants.QUEUE }" not provided at index ${ entryIndex }` );
980
1130
 
981
- if ( settings.cmd4Dbg ) log.debug( `calling addQueue: ${ queueName } type: ${ queueType }` );
982
- addQueue( log, queueName, queueType );
1131
+ if ( settings.cmd4Dbg ) log.debug( `calling addQueue: ${ queueName } type: ${ queueType } retryCount: ${ queueRetryCount }` );
1132
+
1133
+ addQueue( log, queueName, queueType, queueRetryCount );
983
1134
  } );
984
1135
  }
985
1136
 
@@ -3,6 +3,7 @@
3
3
  ## Homebridge UI User. Do not click on any inline links. Homebridge UI does not supprt them. Bug#1098
4
4
 
5
5
  ## ChangeLog
6
+ * <a href="#Whats-new-in-6-3-1">**Whats new in 7.0.0**</a>
6
7
  * <a href="#Whats-new-in-6-3-0">**Whats new in 6.3.0**</a>
7
8
  * <a href="#Whats-new-in-6-2-0">**Whats new in 6.2.0**</a>
8
9
  * <a href="#Whats-new-in-6-1-2">**Whats new in 6.1.2**</a>
@@ -84,6 +85,43 @@
84
85
  * <a href="#Whats-new-in-2-1">**Whats new in 2.1**</a>
85
86
  * <a href="#Whats-new-in-2-0">**Whats new in 2.0**</a>
86
87
 
88
+ <a name="Whats-new-in-6-3-1">## Whats new in 6.3.1</a>
89
+ #### 7.0.0 (2023-03-05)
90
+
91
+ * The reason for the major version numbering update was to for deprecation warnings to throw an error.
92
+ These warnings were there for many major versions and are finally removed.
93
+
94
+ "queueInterval" - Never put into production and will now throw an error.
95
+ "queueMsg" - Never put into production and will now throw an error.
96
+ "queueStatMsgInterval" - Never put into production and will now throw an error.
97
+ "cmd4_Mode" - Obsolete for many versions and will now throw an error.
98
+ "storage" - Obsolete outside of fakegato definition.
99
+ "storagePath" - Obsolete outside of fakegato definition.
100
+ "folder" - Obsolete outside of fakegato definition.
101
+ "keyPath" - Obsolete outside of fakegato definition.
102
+ "queueTypes" - Obsolete inside accessory definition.
103
+
104
+
105
+ ##### New Features
106
+
107
+ * add retries. Also formatting issues ([b8ddf9ce](https://github.com/ztalbot2000/homebridge-cmd4/commit/b8ddf9ceda8ace3a6e820bfad0c4a03c656cf419))
108
+
109
+ ##### Bug Fixes
110
+
111
+ * retry logging starts from zero, but for user count starts from 1 ([38cdf417](https://github.com/ztalbot2000/homebridge-cmd4/commit/38cdf417feebeef2b75dcfec247e6bdfd4739604))
112
+ * By nature retryCount should start from zero ([b8e82ffe](https://github.com/ztalbot2000/homebridge-cmd4/commit/b8e82ffe262c092a301636993544be828a7a34a4))
113
+ * log message in wrong quotes ([6fc555b0](https://github.com/ztalbot2000/homebridge-cmd4/commit/6fc555b0d7bdc20bfc3a38310e3d4f66b968d55d))
114
+ * retries for WoRm should be zero. Can be overriden ([11351633](https://github.com/ztalbot2000/homebridge-cmd4/commit/1135163319c8d16e3886dbf0a0443ba5ed6c4b99))
115
+ * Accessory needs to go unresponsive via updateValue with error object ([cdfee1b2](https://github.com/ztalbot2000/homebridge-cmd4/commit/cdfee1b22ea21dc56edc320768ec6ebea1156cb8))
116
+
117
+ ##### Tests
118
+
119
+ * put back skipped tests ([0b0781fa](https://github.com/ztalbot2000/homebridge-cmd4/commit/0b0781faec7f94e43d67068e15e9505cc7c96414))
120
+ * Remove excess debug messages for commit with verify to work ([ea108470](https://github.com/ztalbot2000/homebridge-cmd4/commit/ea108470631f4abe3377f6d582c962dab141be0f))
121
+ * Don't know why HomeKit does not cause Cmd4 to generate a log that it is trying to reconnect after unavailable ([d45d7c09](https://github.com/ztalbot2000/homebridge-cmd4/commit/d45d7c095d0989c05b88c161a418402711e26677))
122
+ * Add unit testing to prove fix of bug[#130](https://github.com/ztalbot2000/homebridge-cmd4/pull/130) ([e9a902fc](https://github.com/ztalbot2000/homebridge-cmd4/commit/e9a902fcb01fb2ee7c7cb9f2b60e036d0fd5c0d6))
123
+
124
+
87
125
  <a name="Whats-new-in-6-3-0">## Whats new in 6.3.0</a>
88
126
  ### 6.3.0 (2022-04-12)
89
127