diff --git a/Cmd4Accessory.js b/Cmd4Accessory.js index c4802ab..ac34f5a 100644 --- a/Cmd4Accessory.js +++ b/Cmd4Accessory.js @@ -670,24 +670,28 @@ class Cmd4Accessory if ( isPriority == false ) QIndicator = ""; - var transposed = { [ constants.VALUE_lv ]: value, [ constants.RC_lv ]: true, [ constants.MSG_lv ]: "" }; + //var transposed = { [ constants.VALUE_lv ]: value, [ constants.RC_lv ]: true, [ constants.MSG_lv ]: "" }; if ( self.outputConstants == true ) { - transposed = transposeValueToValidConstant( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, value ); + //transposed = transposeValueToValidConstant( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, value ); + value = transposeValueToValidConstant( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, value ); - } else { - - transposed = transposeConstantToValidValue( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, value ); } - if ( transposed.rc == false ) - self.log.warn( `${ self.displayName }: ${ transposed.msg }${ QIndicator }`); + //else { + + //transposed = transposeConstantToValidValue( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, value ); + //} + //if ( transposed.rc == false ) + // self.log.warn( `${ self.displayName }: ${ transposed.msg }${ QIndicator }`); - let valueToSend = transposed.value; + //let valueToSend = transposed.value; - let cmd = self.state_cmd_prefix + self.state_cmd + " Set '" + self.displayName + "' '" + characteristicString + "' '" + valueToSend + "'" + self.state_cmd_suffix; + let cmd = self.state_cmd_prefix + self.state_cmd + " Set '" + self.displayName + "' '" + characteristicString + "' '" + value + "'" + self.state_cmd_suffix; if ( self.statusMsg == "TRUE" ) - self.log.info( chalk.blue( `Setting ${ self.displayName } ${ characteristicString }` ) + ` ${ valueToSend }${ QIndicator }` ); + self.log.info( chalk.blue( `Setting ${ self.displayName } ${ characteristicString }` ) + ` ${ value }${ QIndicator }` ); + + if ( cmd4Dbg ) self.log.debug( `setValue: accTypeEnumIndex:( ${ accTypeEnumIndex } )-"${ characteristicString }" function for: ${ self.displayName } ${ value } cmd: ${ cmd }${ QIndicator }` ); // Execute command to Set a characteristic value for an accessory exec( cmd, { timeout: timeout }, function ( error, stdout, stderr ) @@ -783,31 +787,34 @@ class Cmd4Accessory // a Constant to its valid value. // I can't see this happening, but who knows between upgrades // or restarts. - var transposed = { [ constants.VALUE_lv ]: storedValue, [ constants.RC_lv ]: true, [ constants.MSG_lv ]: "" }; - transposed = transposeConstantToValidValue( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, storedValue ); - if ( transposed.rc == false ) - self.log.warn( `${ self.displayName }: ${ transposed.msg }` ); + //var transposed = { [ constants.VALUE_lv ]: storedValue, [ constants.RC_lv ]: true, [ constants.MSG_lv ]: "" }; + //let transposed = transposeConstantToValidValue( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, storedValue ); + //if ( transposed.rc == false ) + // self.log.warn( `${ self.displayName }: ${ transposed.msg }` ); - let transposedValue = transposed.value; + // let transposedValue = transposed.value; // Return the appropriate type, by seeing what it is defined as // in Homebridge, //let result = self.characteristicValueToItsProperType( self, accTypeEnumIndex, transposedValue ); - let properValue = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].stringConversionFunction( transposedValue ); - if ( properValue == undefined ) - { + //let properValue = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].stringConversionFunction( transposedValue ); + //let properValue = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].stringConversionFunction( transposed ); + //if ( properValue == undefined ) + //{ // If the value is not convertable, just return it. - self.log.warn( `${ self.displayName } ` + chalk.red( `Cannot convert value: ${ transposedValue } to ${ CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].properties.format } for ${ characteristicString }` ) ); + // self.log.warn( `${ self.displayName } ` + chalk.red( `Cannot convert value: ${ transposedValue } to ${ CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].properties.format } for ${ characteristicString }` ) ); - callback( 20, null ); + // callback( 20, null ); - return; - } + // return; + //} - callback( 0, properValue ); + //callback( 0, properValue ); + callback( 0, storedValue ); // Store history using fakegato if set up - self.updateAccessoryAttribute( accTypeEnumIndex, properValue ); + //self.updateAccessoryAttribute( accTypeEnumIndex, properValue ); + self.updateAccessoryAttribute( accTypeEnumIndex, storedValue ); } // *********************************************** @@ -1055,16 +1062,17 @@ class Cmd4Accessory // Even if outputConsts is not set, just in case, transpose // it anyway. - var transposed = { [ constants.VALUE_lv ]: unQuotedReply, [ constants.RC_lv ]: true, [ constants.MSG_lv ]: "" }; - transposed = transposeConstantToValidValue( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, unQuotedReply ) - if ( transposed.rc == false ) - self.log.warn( `${ self.displayName }: ${ transposed.msg }${ QIndicator }` ); + //var transposed = { [ constants.VALUE_lv ]: unQuotedReply, [ constants.RC_lv ]: true, [ constants.MSG_lv ]: "" }; + var transposed = transposeConstantToValidValue( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, unQuotedReply ) + //if ( transposed.rc == false ) + // self.log.warn( `${ self.displayName }: ${ transposed.msg }${ QIndicator }` ); - unQuotedReply = transposed.value; + //unQuotedReply = transposed.value; // Return the appropriate type, by seeing what it is // defined as in Homebridge, - let properValue = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].stringConversionFunction( unQuotedReply ); + //let properValue = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].stringConversionFunction( unQuotedReply ); + let properValue = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].stringConversionFunction( transposed ); if ( properValue == undefined ) { self.log.warn( `${ self.displayName } ` + chalk.red( `Cannot convert value: ${ unQuotedReply } to ${ CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].props.format } for ${ characteristicString }${ QIndicator }` ) ); @@ -1830,13 +1838,13 @@ class Cmd4Accessory if ( Object.keys( CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].validValues ).length > 0 ) { // Even if outputConsts is not set, just in case, transpose it anyway. - var transposed = { [ constants.VALUE_lv ]: value, [ constants.RC_lv ]: true, [ constants.MSG_lv ]: "" }; - transposed = transposeConstantToValidValue( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, value ) ; + //var transposed = { [ constants.VALUE_lv ]: value, [ constants.RC_lv ]: true, [ constants.MSG_lv ]: "" }; + value = transposeConstantToValidValue( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, value ) ; - if ( transposed.rc == false ) - this.log.warn( `${ this.displayName }: ${ transposed.msg }` ); + //if ( transposed.rc == false ) + // this.log.warn( `${ this.displayName }: ${ transposed.msg }` ); - value = transposed.value; + //value = transposed.value; } // Return the appropriate type, by seeing what it is defined as in Homebridge, diff --git a/Cmd4Platform.js b/Cmd4Platform.js index eea8ec4..f3a539f 100644 --- a/Cmd4Platform.js +++ b/Cmd4Platform.js @@ -760,62 +760,13 @@ class Cmd4Platform cmd4PlatformAccessory.setupAccessoryFakeGatoService( cmd4PlatformAccessory.fakegatoConfig ); } - startStaggeredPolling( staggeredPollingArray ) - { - let delay = 0; - let staggeredDelays = [ 3000, 6000, 9000, 12000 ]; - let staggeredDelaysLength = staggeredDelays.length; - let staggeredDelayIndex = 0; - let lastAccessoryUUID = "" - - staggeredPollingArray.forEach( ( entry, entryIndex ) => - { - setTimeout( ( ) => - { - if ( entryIndex == 0 ) - entry.accessory.log.info( `Started staggered kick off of ${ staggeredPollingArray.length } polled characteristics` ); - - if ( cmd4Dbg ) entry.accessory.log.debug( `Kicking off polling for: ${ entry.accessory.displayName } ${ entry.characteristicString } interval:${ entry.interval }, staggered:${ staggeredDelays[ staggeredDelayIndex ] }` ); - entry.accessory.listOfRunningPolls[ entry.accessory.displayName + entry.accTypeEnumIndex ] = - setTimeout( entry.accessory.characteristicPolling.bind( - entry.accessory, entry.accessory, entry.accTypeEnumIndex, entry.characteristicString, entry.timeout, entry.interval ), entry.interval ); - - if ( entryIndex == settings.arrayOfAllStaggeredPollingCharacteristics.length -1 ) - entry.accessory.log.info( `All characteristics are now being polled` ); - - }, delay ); - - - if ( staggeredDelayIndex++ >= staggeredDelaysLength ) - staggeredDelayIndex = 0; - - if ( lastAccessoryUUID != entry.accessory.UUID ) - staggeredDelayIndex = 0; - - lastAccessoryUUID = entry.accessory.UUID; - - delay += staggeredDelays[ staggeredDelayIndex ]; - - }); - } - // The delay definitions are not meant to be changed, except for unit testing // ========================================================================== // staggeredStartDelay - These would be for just polling and to be nice to the system. // queuedStartDelay - As this is both IOS and polling, the delay only happens to // the low priority polling. - startPolling( staggeredStartDelay = 30000, queuedStartDelay = 40000 ) + startPolling( queuedStartDelay = 40000 ) { - if ( settings.arrayOfAllStaggeredPollingCharacteristics.length > 0 ) - { - let pollingTimer = setTimeout( ( ) => - { - this.startStaggeredPolling( settings.arrayOfAllStaggeredPollingCharacteristics ); - }, staggeredStartDelay ); - - this.pollingTimers.push( pollingTimer ); - } - // Check for any queued characteristics if ( Object.keys( settings.listOfCreatedPriorityQueues ).length == 0 ) { diff --git a/Cmd4PriorityPollingQueue.js b/Cmd4PriorityPollingQueue.js index 8137336..9694c75 100644 --- a/Cmd4PriorityPollingQueue.js +++ b/Cmd4PriorityPollingQueue.js @@ -22,7 +22,6 @@ let LOW_PRIORITY_GET = 2; let cmd4Dbg = settings.cmd4Dbg; - class Cmd4PriorityPollingQueue { constructor( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE, queueMsg = constants.DEFAULT_QUEUEMSG, queueStatMsgInterval = constants.DEFAULT_QUEUE_STAT_MSG_INTERVAL ) @@ -62,10 +61,7 @@ class Cmd4PriorityPollingQueue { let self = this; - // Call the callback immediately as we will call updateValue - callback( ); - - 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.VALUE_lv ]: value }; + 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 }; // Determine wherebto put theventry in the queue if ( self.queue.highPriorityQueue.length == 0 ) @@ -107,10 +103,6 @@ class Cmd4PriorityPollingQueue { let self = this; - // Call the callback immediately as we will call updateValue - // Homebridge does not like an empty callback for "Gets" - callback( null, self.getStoredValueForIndex( accTypeEnumIndex ) ); - self.queue.highPriorityQueue.push( { [ constants.IS_SET_lv ]: false, [ constants.QUEUE_GET_IS_UPDATE_lv ]: false, [ 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 } ); self.queue.processQueue( HIGH_PRIORITY_GET, self.queue ); @@ -219,9 +211,9 @@ class Cmd4PriorityPollingQueue // Nothing special was done for casing on errors, so omit it. if ( error == 0 ) { - //if ( entry.queueGetIsUpdate == false ) - // entry.callback( error, properValue ); - //else + if ( entry.queueGetIsUpdate == false ) + entry.callback( error, properValue ); + else entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( properValue ); // A good anything, updates the lastGoodTransactionTime diff --git a/utils/transposeCMD4Props.js b/utils/transposeCMD4Props.js index 706c1cc..9a54ae1 100644 --- a/utils/transposeCMD4Props.js +++ b/utils/transposeCMD4Props.js @@ -29,7 +29,8 @@ var transposeConstantToValidValue = function ( CMD4_ENUM_properties_obj, accType { // Return the original as it should be used instead of nothing // This is not a failure - return { "value": constantString, "rc": true, "msg": `Non Convertible characteristic ${ constantString } for ${ CMD4_ENUM_properties_obj[ accTypeEnumIndex ].type }` }; + //return { "value": constantString, "rc": true, "msg": `Non Convertible characteristic ${ constantString } for ${ CMD4_ENUM_properties_obj[ accTypeEnumIndex ].type }` }; + return constantString; } // In case constantString is not a string, ie false @@ -38,17 +39,19 @@ var transposeConstantToValidValue = function ( CMD4_ENUM_properties_obj, accType if ( Object.prototype.hasOwnProperty.call( CMD4_ENUM_properties_obj[ accTypeEnumIndex ].validValues, ucConstantString ) ) { - let value = CMD4_ENUM_properties_obj[ accTypeEnumIndex ].validValues[ ucConstantString ]; + // let value = CMD4_ENUM_properties_obj[ accTypeEnumIndex ].validValues[ ucConstantString ]; + return CMD4_ENUM_properties_obj[ accTypeEnumIndex ].validValues[ ucConstantString ]; - return { "value": value, "rc": true, "msg": "Transpose success" }; + //return { "value": value, "rc": true, "msg": "Transpose success" }; } // What if it is already transposed correctly? - let constant = extractKeyValue( CMD4_ENUM_properties_obj[ accTypeEnumIndex ].validValues, constantString ); - if ( constant == undefined || constant == null ) - return { "value": constantString, "rc": false, "msg": `Cannot convert ${ constantString } to a value for ${ CMD4_ENUM_properties_obj[ accTypeEnumIndex ].type }` }; - else - return { "value": constantString, "rc": true, "msg": "Already transposed" }; + // let constant = extractKeyValue( CMD4_ENUM_properties_obj[ accTypeEnumIndex ].validValues, constantString ); + // if ( constant == undefined || constant == null ) + // return { "value": constantString, "rc": false, "msg": `Cannot convert ${ constantString } to a value for ${ CMD4_ENUM_properties_obj[ accTypeEnumIndex ].type }` }; + //else + // return { "value": constantString, "rc": true, "msg": "Already transposed" }; + return constantString; } // Used to convet ValidValues Value to its corresponding Constant. @@ -58,7 +61,8 @@ var transposeValueToValidConstant = function ( CMD4_ENUM_properties_obj, accType { // Return the original as it should be used instead of nothing // This is not a failure - return { "value": valueString, "rc": true, "msg": `Non Convertible characteristic ${ valueString } for ${ CMD4_ENUM_properties_obj[ accTypeEnumIndex ].type }` }; + //return { "value": valueString, "rc": true, "msg": `Non Convertible characteristic ${ valueString } for ${ CMD4_ENUM_properties_obj[ accTypeEnumIndex ].type }` }; + return valueString; } let constant = extractKeyValue( CMD4_ENUM_properties_obj[ accTypeEnumIndex ].validValues, valueString ); @@ -66,14 +70,17 @@ var transposeValueToValidConstant = function ( CMD4_ENUM_properties_obj, accType if ( constant == undefined || constant == null ) { // What if it is already transposed correctly? - let value = CMD4_ENUM_properties_obj[ accTypeEnumIndex ].validValues[ valueString ]; - if ( value == undefined || value == null ) - return { "value": valueString, "rc": false, "msg": `Cannot convert ${ valueString } to a constant for ${ CMD4_ENUM_properties_obj[ accTypeEnumIndex ].type }` }; - else - return { "value": valueString, "rc": true, "msg": "Already transposed" }; + //let value = CMD4_ENUM_properties_obj[ accTypeEnumIndex ].validValues[ valueString ]; + //if ( value == undefined || value == null ) + // return { "value": valueString, "rc": false, "msg": `Cannot convert ${ valueString } to a constant for ${ CMD4_ENUM_properties_obj[ accTypeEnumIndex ].type }` }; + //else + // return { "value": valueString, "rc": true, "msg": "Already transposed" }; + + return valueString; } - return { "value": constant, "rc": true, "msg": "Transpose success" }; + // return { "value": constant, "rc": true, "msg": "Transpose success" }; + return constant; }