homebridge-cmd4 5.1.0 → 6.0.1

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.
@@ -16,7 +16,7 @@ const constants = require( "./cmd4Constants" );
16
16
  var chalk = require( "chalk" );
17
17
 
18
18
  let trueTypeOf = require( "./utils/trueTypeOf" );
19
- let ucFirst = require( "./utils/ucFirst" );
19
+ let lcFirst = require( "./utils/lcFirst" );
20
20
 
21
21
  // For changing validValue Constants to Values and back again
22
22
  var { transposeConstantToValidValue,
@@ -29,8 +29,6 @@ let HIGH_PRIORITY_SET = 0;
29
29
  let HIGH_PRIORITY_GET = 1;
30
30
  let LOW_PRIORITY_GET = 2;
31
31
 
32
- let cmd4Dbg = settings.cmd4Dbg;
33
-
34
32
  class Cmd4PriorityPollingQueue
35
33
  {
36
34
  constructor( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE )
@@ -38,7 +36,7 @@ class Cmd4PriorityPollingQueue
38
36
  this.log = log;
39
37
 
40
38
  // This works better for Unit testing
41
- cmd4Dbg = log.debugEnabled;
39
+ settings.cmd4Dbg = log.debugEnabled;
42
40
 
43
41
  this.queueName = queueName;
44
42
  this.queueType = queueType;
@@ -76,7 +74,7 @@ class Cmd4PriorityPollingQueue
76
74
  let self = this;
77
75
 
78
76
  // Save the value to cache. The set will come later
79
- self.setStoredValueForIndex( accTypeEnumIndex, value );
77
+ self.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, value );
80
78
  callback( 0 );
81
79
 
82
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 };
@@ -90,7 +88,7 @@ class Cmd4PriorityPollingQueue
90
88
  } else {
91
89
 
92
90
  // Make sure that this is the latest "Set" of this entry
93
- let index = self.queue.highPriorityQueue.findIndex( ( entry ) => entry.accessory.UUID == self.UUID && entry.isSet == true && entry.accTypeEnumIndex == accTypeEnumIndex );
91
+ let index = self.queue.highPriorityQueue.findIndex( ( entry ) => entry.accessory.uuid == self.uuid && entry.isSet == true && entry.accTypeEnumIndex == accTypeEnumIndex );
94
92
 
95
93
  if ( index == -1 )
96
94
  {
@@ -121,7 +119,7 @@ class Cmd4PriorityPollingQueue
121
119
  let self = this;
122
120
 
123
121
  // return the cached value
124
- let storedValue = self.getStoredValueForIndex( accTypeEnumIndex );
122
+ let storedValue = self.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex );
125
123
  callback( 0, storedValue );
126
124
 
127
125
  // When the value is returned, it will update homebridge
@@ -139,7 +137,7 @@ class Cmd4PriorityPollingQueue
139
137
 
140
138
  processHighPrioritySetQueue( entry )
141
139
  {
142
- if ( cmd4Dbg ) this.log.debug( `Processing high priority queue "Set" entry: ${ entry.accTypeEnumIndex } length: ${ this.highPriorityQueue.length }` );
140
+ if ( settings.cmd4Dbg ) this.log.debug( `Processing high priority queue "Set" entry: ${ entry.accTypeEnumIndex } length: ${ this.highPriorityQueue.length }` );
143
141
 
144
142
  this.inProgressSets ++;
145
143
  this.qSetValue( entry.accessory, entry.accTypeEnumIndex, entry.characteristicString, entry.timeout, entry.value, function ( error )
@@ -213,7 +211,7 @@ class Cmd4PriorityPollingQueue
213
211
 
214
212
  processHighPriorityGetQueue( entry )
215
213
  {
216
- if ( cmd4Dbg ) this.log.debug( `Processing high priority queue "Get" entry: ${ entry.accTypeEnumIndex } isUpdate: ${ entry.queueGetIsUpdate } length: ${ this.highPriorityQueue.length }` );
214
+ if ( settings.cmd4Dbg ) this.log.debug( `Processing high priority queue "Get" entry: ${ entry.accTypeEnumIndex } isUpdate: ${ entry.queueGetIsUpdate } length: ${ this.highPriorityQueue.length }` );
217
215
 
218
216
  this.inProgressGets ++;
219
217
 
@@ -253,7 +251,7 @@ class Cmd4PriorityPollingQueue
253
251
 
254
252
  processEntryFromLowPriorityQueue( entry )
255
253
  {
256
- if ( cmd4Dbg ) this.log.debug( `Processing low priority queue entry: ${ entry.accTypeEnumIndex }` );
254
+ if ( settings.cmd4Dbg ) this.log.debug( `Processing low priority queue entry: ${ entry.accTypeEnumIndex }` );
257
255
 
258
256
  let queue = entry.accessory.queue;
259
257
 
@@ -308,7 +306,7 @@ class Cmd4PriorityPollingQueue
308
306
 
309
307
  let cmd = self.state_cmd_prefix + self.state_cmd + " Get '" + self.displayName + "' '" + characteristicString + "'" + self.state_cmd_suffix;
310
308
 
311
- if ( cmd4Dbg ) self.log.debug( `getValue: accTypeEnumIndex:( ${ accTypeEnumIndex } )-"${ characteristicString }" function for: ${ self.displayName } cmd: ${ cmd } timeout: ${ timeout }` );
309
+ if ( settings.cmd4Dbg ) self.log.debug( `getValue: accTypeEnumIndex:( ${ accTypeEnumIndex } )-"${ characteristicString }" function for: ${ self.displayName } cmd: ${ cmd } timeout: ${ timeout }` );
312
310
 
313
311
  let reply = "NxN";
314
312
 
@@ -415,11 +413,11 @@ class Cmd4PriorityPollingQueue
415
413
  self.log.warn( `getValue: Warning, Retrieving ${ characteristicString }, expected only one word value for: ${ self.displayName } of: ${ trimmedReply }` );
416
414
  }
417
415
 
418
- if ( cmd4Dbg ) self.log.debug( `getValue: ${ characteristicString } function for: ${ self.displayName } returned: ${ unQuotedReply }` );
416
+ if ( settings.cmd4Dbg ) self.log.debug( `getValue: ${ characteristicString } function for: ${ self.displayName } returned: ${ unQuotedReply }` );
419
417
 
420
418
 
421
419
  var transposed = transposeConstantToValidValue( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, unQuotedReply )
422
- if ( cmd4Dbg && transposed != unQuotedReply ) self.log.debug( `getValue: ${ characteristicString } for: ${ self.displayName } transposed: ${ transposed }` );
420
+ if ( settings.cmd4Dbg && transposed != unQuotedReply ) self.log.debug( `getValue: ${ characteristicString } for: ${ self.displayName } transposed: ${ transposed }` );
423
421
 
424
422
 
425
423
  // Return the appropriate type, by seeing what it is
@@ -434,7 +432,7 @@ class Cmd4PriorityPollingQueue
434
432
  return;
435
433
  }
436
434
 
437
- if ( cmd4Dbg && properValue != transposed ) self.log.debug( `getValue: ${ characteristicString } for: ${ self.displayName } properValue: ${ properValue }` );
435
+ if ( settings.cmd4Dbg && properValue != transposed ) self.log.debug( `getValue: ${ characteristicString } for: ${ self.displayName } properValue: ${ properValue }` );
438
436
 
439
437
  // Success !!!!
440
438
  callback( 0, properValue );
@@ -479,7 +477,7 @@ class Cmd4PriorityPollingQueue
479
477
  let self = accessory;
480
478
  let queue = accessory.queue;
481
479
 
482
- if ( self.outputConstants == true )
480
+ if ( self.hV.outputConstants == true )
483
481
  {
484
482
  value = transposeValueToValidConstant( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, value );
485
483
 
@@ -490,10 +488,10 @@ class Cmd4PriorityPollingQueue
490
488
 
491
489
  let cmd = accessory.state_cmd_prefix + accessory.state_cmd + " Set '" + accessory.displayName + "' '" + characteristicString + "' '" + value + "'" + accessory.state_cmd_suffix;
492
490
 
493
- if ( accessory.statusMsg == "TRUE" )
491
+ if ( accessory.hV.statusMsg == "TRUE" )
494
492
  self.log.info( chalk.blue( `Setting ${ self.displayName } ${ characteristicString }` ) + ` ${ value }` );
495
493
 
496
- if ( cmd4Dbg ) self.log.debug( `setValue: accTypeEnumIndex:( ${ accTypeEnumIndex } )-"${ characteristicString }" function for: ${ self.displayName } ${ value } cmd: ${ cmd } timeout: ${ timeout }` );
494
+ if ( settings.cmd4Dbg ) self.log.debug( `setValue: accTypeEnumIndex:( ${ accTypeEnumIndex } )-"${ characteristicString }" function for: ${ self.displayName } ${ value } cmd: ${ cmd } timeout: ${ timeout }` );
497
495
 
498
496
  // Execute command to Set a characteristic value for an accessory
499
497
  let child = exec( cmd, { timeout: timeout }, function ( error, stdout, stderr )
@@ -608,7 +606,7 @@ class Cmd4PriorityPollingQueue
608
606
  return false;
609
607
 
610
608
  } else {
611
- if ( cmd4Dbg ) this.log.debug( `Unhandled lastTransactionType: ${ lastTransactionType } inProgressSets: ${ queue.inProgressSets } inProgressGets: ${ queue.inProgressGets } queueStarted: ${ queue.queueStarted } lowQueueLen: ${ queue.lowPriorityQueue.length } hiQueueLen: ${ queue.highPriorityQueue.length }` );
609
+ if ( settings.cmd4Dbg ) this.log.debug( `Unhandled lastTransactionType: ${ lastTransactionType } inProgressSets: ${ queue.inProgressSets } inProgressGets: ${ queue.inProgressGets } queueStarted: ${ queue.queueStarted } lowQueueLen: ${ queue.lowPriorityQueue.length } hiQueueLen: ${ queue.highPriorityQueue.length }` );
612
610
 
613
611
  }
614
612
  }
@@ -679,7 +677,7 @@ class Cmd4PriorityPollingQueue
679
677
  return false;
680
678
 
681
679
  } else {
682
- if ( cmd4Dbg ) this.log.debug( `Unhandled lastTransactionType: ${ lastTransactionType } inProgressSets: ${ queue.inProgressSets } inProgressGets: ${ queue.inProgressGets } queueStarted: ${ queue.queueStarted } lowQueueLen: ${ queue.lowPriorityQueue.length } hiQueueLen: ${ queue.highPriorityQueue.length }` );
680
+ if ( settings.cmd4Dbg ) this.log.debug( `Unhandled lastTransactionType: ${ lastTransactionType } inProgressSets: ${ queue.inProgressSets } inProgressGets: ${ queue.inProgressGets } queueStarted: ${ queue.queueStarted } lowQueueLen: ${ queue.lowPriorityQueue.length } hiQueueLen: ${ queue.highPriorityQueue.length }` );
683
681
 
684
682
  }
685
683
  }
@@ -711,7 +709,7 @@ class Cmd4PriorityPollingQueue
711
709
  let self = entry.accessory;
712
710
  let queue = entry.accessory.queue;
713
711
 
714
- if ( cmd4Dbg ) self.log.debug( `Scheduling Poll of index: ${ entry.accTypeEnumIndex } characteristic: ${ entry.characteristicString } for: ${ self.displayName } timeout: ${ entry.timeout } interval: ${ entry.interval }` );
712
+ if ( settings.cmd4Dbg ) self.log.debug( `Scheduling Poll of index: ${ entry.accTypeEnumIndex } characteristic: ${ entry.characteristicString } for: ${ self.displayName } timeout: ${ entry.timeout } interval: ${ entry.interval }` );
715
713
 
716
714
  // Clear polling
717
715
  if ( queue.listOfRunningPolls &&
@@ -723,7 +721,7 @@ class Cmd4PriorityPollingQueue
723
721
  // If the queue was busy/not available, schedule the entry at a later time
724
722
  if ( queue.processQueueFunc( LOW_PRIORITY_GET, queue, entry ) == false )
725
723
  {
726
- if ( cmd4Dbg ) self.log.debug( `processsQueue returned false` );
724
+ if ( settings.cmd4Dbg ) self.log.debug( `processsQueue returned false` );
727
725
 
728
726
  queue.scheduleLowPriorityEntry( entry );
729
727
  }
@@ -782,7 +780,7 @@ class Cmd4PriorityPollingQueue
782
780
  let lastAccessoryUUID = ""
783
781
  let allDoneCount = 0;
784
782
 
785
- if ( cmd4Dbg ) this.log.debug( `enablePolling for the first time` );
783
+ if ( settings.cmd4Dbg ) this.log.debug( `enablePolling for the first time` );
786
784
 
787
785
  // If there is nothing in the lowPriorityQueue, we are dome.
788
786
  // Demo mode or Unit testing.
@@ -799,19 +797,19 @@ class Cmd4PriorityPollingQueue
799
797
  allDoneCount ++;
800
798
  setTimeout( ( ) =>
801
799
  {
802
- if ( entryIndex == 0 && cmd4Dbg )
800
+ if ( entryIndex == 0 && settings.cmd4Dbg )
803
801
  if ( queue.queueType == constants.QUEUETYPE_WORM )
804
802
  entry.accessory.log.debug( `Started staggered kick off of ${ queue.lowPriorityQueue.length } polled characteristics for queue: "${ entry.accessory.queue.queueName }"` );
805
803
  else
806
804
  entry.accessory.log.debug( `Started staggered kick off of ${ queue.lowPriorityQueue.length } polled characteristics for "${ entry.accessory.displayName }"` );
807
805
 
808
- if ( cmd4Dbg ) entry.accessory.log.debug( `Kicking off polling for: ${ entry.accessory.displayName } ${ entry.characteristicString } interval:${ entry.interval }, staggered:${ staggeredDelays[ staggeredDelayIndex ] }` );
806
+ if ( settings.cmd4Dbg ) entry.accessory.log.debug( `Kicking off polling for: ${ entry.accessory.displayName } ${ entry.characteristicString } interval:${ entry.interval }, staggered:${ staggeredDelays[ staggeredDelayIndex ] }` );
809
807
 
810
808
  queue.scheduleLowPriorityEntry( entry );
811
809
 
812
810
  if ( entryIndex == queue.lowPriorityQueue.length -1 )
813
811
  {
814
- if ( cmd4Dbg )
812
+ if ( settings.cmd4Dbg )
815
813
  if ( queue.queueType == constants.QUEUETYPE_WORM )
816
814
  entry.accessory.log.debug( `All characteristics are now being polled for queue: "${ queue.queueName }"` );
817
815
  else
@@ -824,10 +822,10 @@ class Cmd4PriorityPollingQueue
824
822
  if ( staggeredDelayIndex++ >= staggeredDelaysLength )
825
823
  staggeredDelayIndex = 0;
826
824
 
827
- if ( lastAccessoryUUID != entry.accessory.UUID )
825
+ if ( lastAccessoryUUID != entry.accessory.uuid )
828
826
  staggeredDelayIndex = 0;
829
827
 
830
- lastAccessoryUUID = entry.accessory.UUID;
828
+ lastAccessoryUUID = entry.accessory.uuid;
831
829
 
832
830
  delay += staggeredDelays[ staggeredDelayIndex ];
833
831
 
@@ -858,7 +856,7 @@ class Cmd4PriorityPollingQueue
858
856
  this.processQueueFunc = this.processWormQueue;
859
857
  // When not in debug mode, do not echo errors for the WoRm queue
860
858
  // as errors are handled through retries.
861
- if ( ! cmd4Dbg )
859
+ if ( ! settings.cmd4Dbg )
862
860
  this.echoE = false;
863
861
  break;
864
862
  case constants.QUEUETYPE_STANDARD:
@@ -877,7 +875,7 @@ class Cmd4PriorityPollingQueue
877
875
  isCharacteristicPolled( accTypeEnumIndex, queue, accessory )
878
876
  {
879
877
  if ( queue.lowPriorityQueue.filter(
880
- entry => entry.accessory.UUID == accessory.UUID &&
878
+ entry => entry.accessory.uuid == accessory.uuid &&
881
879
  entry.accTypeEnumIndex == accTypeEnumIndex
882
880
  ).length == 0 )
883
881
  {
@@ -922,10 +920,17 @@ var parseAddQueueTypes = function ( log, entrys )
922
920
 
923
921
  for ( let key in entry )
924
922
  {
923
+ let lcKey = lcFirst( key );
924
+
925
+ // warn now
926
+ if ( key.charAt( 0 ) === key.charAt( 0 ).toUpperCase( ) )
927
+ {
928
+ log.warn( `The config.json queueTypes key: ${ key } is Capitalized. All keys in the near future will ALWAYS start with a lower case character for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
929
+ }
930
+
925
931
  let value = entry[ key ];
926
- let ucKey = ucFirst( key );
927
932
 
928
- switch( ucKey )
933
+ switch( lcKey )
929
934
  {
930
935
  case constants.QUEUE:
931
936
  if ( settings.listOfCreatedPriorityQueues[ entry.queue ] )
@@ -945,19 +950,7 @@ var parseAddQueueTypes = function ( log, entrys )
945
950
 
946
951
  break;
947
952
  case "QueueInterval":
948
-
949
- // Never put into production
950
- log.warn( `Warning: ${ key } has been deprecated. It was never really used anyway.` );
951
- log.warn( `To remove this message, just remove ${ key } from your config.json` );
952
-
953
- break;
954
953
  case "QueueMsg":
955
-
956
- // Never put into production
957
- log.warn( `Warning: ${ key } has been deprecated. It was never really used anyway.` );
958
- log.warn( `To remove this message, just remove ${ key } from your config.json` );
959
-
960
- break;
961
954
  case "QueueStatMsgInterval":
962
955
 
963
956
  // Never put into production
@@ -974,7 +967,7 @@ var parseAddQueueTypes = function ( log, entrys )
974
967
  if ( queueName == null )
975
968
  throw new Error( `"${ constants.QUEUE }" not provided at index ${ entryIndex }` );
976
969
 
977
- if ( cmd4Dbg ) log.debug( `calling addQueue: ${ queueName } type: ${ queueType }` );
970
+ if ( settings.cmd4Dbg ) log.debug( `calling addQueue: ${ queueName } type: ${ queueType }` );
978
971
  addQueue( log, queueName, queueType );
979
972
  } );
980
973
  }
@@ -14,8 +14,8 @@
14
14
  // - chmod u+x $HOME/.homebridge/Cmd4Scripts/State.js
15
15
  //
16
16
  // Parameters are:
17
- // Get <accessory name> <characteristic>
18
- // Set <accessory name> <characteristic> <value>
17
+ // Get <Accessory name> <Characteristic>
18
+ // Set <Accessory name> <Characteristic> <value>
19
19
  //
20
20
  // Note 1: These paramaters match the those of the Cmd4 plugin.
21
21
  // Note 2: All characteristics of the HomeKit Accessory Protocol (HAP)
@@ -12,8 +12,8 @@
12
12
 
13
13
  Parameters:
14
14
  ===========
15
- Get < any accessory name > < characteristic >
16
- Set < any accessory name > < characteristic > < value >
15
+ Get < Any accessory name > < Characteristic >
16
+ Set < Any accessory name > < Characteristic > < value >
17
17
 
18
18
  Notes:
19
19
  =====
@@ -287,7 +287,7 @@ switch( io )
287
287
  writeData( device, characteristic, option );
288
288
 
289
289
  // Set to done
290
- writeData( device,"SecuritySystemAlarmState", option );
290
+ writeData( device,"SecuritySystemCurrentState", option );
291
291
 
292
292
  break;
293
293
  }
@@ -15,9 +15,9 @@
15
15
  # "lockCurrentState": "SECURED",
16
16
  # "lockTargetState": "SECURED",
17
17
  # "name": "Front Door",
18
- # "Manufacturer": "XYZ",
19
- # "Model": "XYZ",
20
- # "SerialNumber": "GPIO 24",
18
+ # "manufacturer": "XYZ",
19
+ # "model": "XYZ",
20
+ # "serialNumber": "GPIO 24",
21
21
  # "polling": [
22
22
  # {
23
23
  # "characteristic": "lockCurrentState",
@@ -6,8 +6,8 @@
6
6
  // of your own
7
7
  //
8
8
  // Parameters are:
9
- // Get < any accessory name > < characteristic >
10
- // Set < any accessory name > < characteristic > < value >
9
+ // Get < Any accessory name > < Characteristic >
10
+ // Set < Any accessory name > < Characteristic > < value >
11
11
  //
12
12
  // Note 1: These paramaters match the those of the Cmd4 plugin.
13
13
  // A full lost of supported devices and characteristics can be
@@ -7,8 +7,8 @@
7
7
  # of your own
8
8
  #
9
9
  # Parameters are:
10
- # Get < any accessory name > < characteristic>
11
- # Set < any accessory name > < characteristic> < value >
10
+ # Get < Any accessory name > < Characteristic>
11
+ # Set < Any accessory name > < Characteristic> < value >
12
12
  #
13
13
  # Note 1: These paramaters match the those of the Cmd4 plugin.
14
14
  # A full lost of supported devices and characteristics can be
@@ -40,8 +40,8 @@ characteristic=""
40
40
  option=""
41
41
 
42
42
  if [ $length -le 1 ]; then
43
- printf "Usage: $0 Get < AccessoryName > < characteristic >\n"
44
- printf "Usage: $0 Set < AccessoryName > < characteristic > < Value >\n"
43
+ printf "Usage: $0 Get < AccessoryName > < Characteristic >\n"
44
+ printf "Usage: $0 Set < AccessoryName > < Characteristic > < Value >\n"
45
45
  exit -1
46
46
  fi
47
47