diff --git a/Cmd4Accessory.js b/Cmd4Accessory.js index 858516f..0f648a5 100644 --- a/Cmd4Accessory.js +++ b/Cmd4Accessory.js @@ -105,7 +105,11 @@ class Cmd4Accessory // Bring the parent config variables forward. // If they do not exist, they would still be undefined. - this.stateChangeResponseTime = ( parentInfo && parentInfo.stateChangeResponseTime ) ? parentInfo.stateChangeResponseTime : constants.DEFAULT_INTERVAL; + // For stateChangeResponseTime, if not the parentInfo, then + // it gets defined by the accessoryType devicesStateChangeDefaultTime + if ( parentInfo && parentInfo.stateChangeResponseTime ) + this.stateChangeResponseTime = parentInfo.stateChangeResponseTime; + this.interval = ( parentInfo && parentInfo.interval ) ? parentInfo.interval : constants.DEFAULT_INTERVAL; this.timeout = ( parentInfo && parentInfo.timeout ) ? parentInfo.timeout : constants.DEFAULT_TIMEOUT; this.statusMsg = ( parentInfo && parentInfo.statusMsg ) ? parentInfo.statusMsg : constants.DEFAULT_STATUSMSG; @@ -142,7 +146,7 @@ class Cmd4Accessory // number or MAC address. let UUID = getAccessoryUUID( config, this.api.hap.uuid ); - let existingData = this.STORED_DATA_ARRAY.find( data => data[constants.UUID] === UUID ); + let existingData = this.STORED_DATA_ARRAY.find( data => data[ constants.UUID ] === UUID ); if ( existingData ) { this.log.debug(`Cmd4Accessory: found existingData for ${ this.displayName }` ); @@ -159,8 +163,8 @@ class Cmd4Accessory // restarts. this.storedValuesPerCharacteristic = new Array( CMD4_ACC_TYPE_ENUM.EOL ).fill( null ); - this.STORED_DATA_ARRAY.push( { [constants.UUID]: UUID, - [constants.storedValuesPerCharacteristic]: this.storedValuesPerCharacteristic + this.STORED_DATA_ARRAY.push( { [ constants.UUID ]: UUID, + [ constants.storedValuesPerCharacteristic ]: this.storedValuesPerCharacteristic } ); } @@ -641,7 +645,7 @@ class Cmd4Accessory let characteristicString = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type; - var transposed = { "value": value, "rc": true, "msg": "" }; + 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 ); @@ -751,7 +755,7 @@ class Cmd4Accessory // a Constant to its valid value. // I can't see this happening, but who knows between upgrades // or restarts. - var transposed = { "value": storedValue, "rc": true, "msg": "" }; + 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 }`); @@ -1017,7 +1021,7 @@ class Cmd4Accessory // Even if outputConsts is not set, just in case, transpose // it anyway. - var transposed = { "value": unQuotedReply, "rc": true, "msg": "" }; + 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 }`); @@ -1778,7 +1782,7 @@ 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 = { "value": value, "rc": true, "msg": "" }; + var transposed = { [ constants.VALUE_lv ]: value, [ constants.RC_lv ]: true, [ constants.MSG_lv ]: "" }; transposed = transposeConstantToValidValue( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, value ) ; if ( transposed.rc == false ) @@ -2267,7 +2271,7 @@ class Cmd4Accessory if ( this.CMD4 == constants.PLATFORM && ( ! this.publishExternally || ! this.category ) || this.CMD4 == constants.STANDALONE ) { - this.log.warn( 'Televisions should be Platform Accessories with "publishExternally": true, "category": "TELEVISION"' ); + this.log.warn( `Televisions should be Platform Accessories with "${ constants.PUBLISHEXTERNALLY }": true, "${ constants.CATEGORY }": "TELEVISION"` ); } if ( this.CMD4 == constants.PLATFORM && ! this.publishExternally && ( numberOfTVsPerBridge += 1 ) > 1 ) { @@ -2333,6 +2337,10 @@ class Cmd4Accessory // Heirarchy is first the default let timeout = constants.DEFAULT_TIMEOUT; let interval = constants.DEFAULT_INTERVAL; + let stateChangeResponseTime = constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME; + if ( ! accessory.stateChangeResponseTime ) + stateChangeResponseTime = CMD4_DEVICE_TYPE_ENUM.properties[ accessory.typeIndex ].devicesStateChangeDefaultTime; + let queueName = constants.DEFAULT_QUEUE_NAME; // Secondly the accessories definition @@ -2354,11 +2362,13 @@ class Cmd4Accessory timeout = pollingEntrys[0].timeout; if ( pollingEntrys[0].interval ) interval = pollingEntrys[0].interval; + if ( pollingEntrys[0].stateChangeResponseTime ) + stateChangeResponseTime = pollingEntrys[0].stateChangeResponseTime; if ( pollingEntrys[0].queueName ) queueName = pollingEntrys[0].queueName; } - return { "timeout": timeout, "interval": interval, "queueName": queueName }; + return { [ constants.TIMEOUT_lv ]: timeout, [ constants.INTERVAL_lv ]: interval, [ constants.STATE_CHANGE_RESPONSE_TIME_lv ]: stateChangeResponseTime, [ constants.QUEUE_NAME_lv ]: queueName }; } @@ -2390,7 +2400,7 @@ class Cmd4Accessory let jsonPollingConfig = accessory.polling[ jsonIndex ]; queueName = constants.DEFAULT_QUEUE_NAME; - // The default timeout is defined frist by the accessory, and if not defined, + // The default timeout is defined first by the accessory, and if not defined, // then the default 1 minute. Timeouts are in milliseconds let timeout = ( this.timeout ) ? this.timeout : constants.DEFAULT_TIMEOUT; @@ -2398,6 +2408,10 @@ class Cmd4Accessory // then the default 1 minute interval. Intervals are in seconds let interval = ( this.interval ) ? this.interval : constants.DEFAULT_INTERVAL; + // The default stateChangeResponseTime is defined first by the accessory, and if not defined, + // then the default 3 seconds. stateChangeResponseTime is in seconds + let stateChangeResponseTime = ( this.stateChangeResponseTime ) ? this.stateChangeResponseTime : constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME; + let value; let accTypeEnumIndex = -1; @@ -2419,6 +2433,11 @@ class Cmd4Accessory case constants.INTERVAL: // Intervals are in seconds interval = parseInt( value, 10 ) * 1000; + break; + case constants.STATECHANGERESPONSETIME: + // respnse time is in seconds + stateChangeResponseTime = value * 1000; + break; case constants.QUEUE: { @@ -2492,7 +2511,7 @@ class Cmd4Accessory log.debug( `Setting up accessory: ${ accessory.displayName } for polling of: ${ CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type } timeout: ${ timeout } interval: ${ interval }` ); - settings.arrayOfPollingCharacteristics.push( {"accessory": accessory, "accTypeEnumIndex": accTypeEnumIndex, "interval": interval, "timeout": timeout, "queueName": queueName } ); + settings.arrayOfPollingCharacteristics.push( { [ constants.ACCESSORY_lv ]: accessory, [ constants.ACC_TYPE_ENUM_INDEX_lv ]: accTypeEnumIndex, [ constants.INTERVAL_lv ]: interval, [ constants.TIMEOUT_lv ]: timeout, [ constants.STATE_CHANGE_RESPONSE_TIME_lv ]: stateChangeResponseTime, [ constants.QUEUE_NAME_lv ]: queueName } ); } break; @@ -2511,7 +2530,7 @@ class Cmd4Accessory // Make sure the defined characteristics will be polled CMD4_DEVICE_TYPE_ENUM.properties[ accessory.typeIndex ].defaultPollingCharacteristics.forEach( defaultPollingAccTypeEnumIndex => { - settings.arrayOfPollingCharacteristics.push( {"accessory": accessory, "accTypeEnumIndex": defaultPollingAccTypeEnumIndex, "timeout": accessory.timeout } ); + settings.arrayOfPollingCharacteristics.push( { [ constants.ACCESSORY_lv ]: accessory, [ constants.ACC_TYPE_ENUM_INDEX_lv ]: defaultPollingAccTypeEnumIndex, [ constants.INTERVAL_lv ]: accessory.interval, [ constants.TIMEOUT_lv ]: accessory.timeout, [ constants.STATE_CHANGE_RESPONSE_TIME_lv ]: constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME, [ constants.QUEUE_NAME_lv ]: constants.DEFAULT_QUEUE_NAME } ); }); } diff --git a/Cmd4Platform.js b/Cmd4Platform.js index 351f7bd..98620e0 100644 --- a/Cmd4Platform.js +++ b/Cmd4Platform.js @@ -778,16 +778,16 @@ class Cmd4Platform let details = self.lookupDetailsForPollingCharacteristic( self, accTypeEnumIndex ); let specificQueue = settings.listOfCreatedPriorityQueues[ details.queueName ]; // Add To Top of priority queue - // ( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, callback, value ) - specificQueue.addQueueEntry( false, false, self, accTypeEnumIndex, details.interval, details.timeout, callback, null ); + // ( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, stateChangeResponseTime, callback, value ) + specificQueue.addQueueEntry( false, false, self, accTypeEnumIndex, details.interval, details.timeout, details.stateChangeResponseTime, callback, null ); } prioritySetValue( accTypeEnumIndex, value, callback ) { let self = this; let details = self.lookupDetailsForPollingCharacteristic( self, accTypeEnumIndex ); let specificQueue = settings.listOfCreatedPriorityQueues[ details.queueName ]; - //specificQueue.addQueueEntry( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, callback, value ) - specificQueue.addQueueEntry( true, false, self, accTypeEnumIndex, details.interval, details.timeout, callback, value ) + //specificQueue.addQueueEntry( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, stateChangeResponseTime, callback, value ) + specificQueue.addQueueEntry( true, false, self, accTypeEnumIndex, details.interval, details.timeout, details.stateChangeResponseTime, callback, value ) // todo if ( relatedCharacteristic ) // todo AddToTopOfQueueBehindSet( get } @@ -845,8 +845,8 @@ class Cmd4Platform settings.listOfCreatedPriorityQueues[ elem.queueName ] = queue; } this.log.debug( `Adding ${ elem.accessory.displayName } ${ CMD4_ACC_TYPE_ENUM.properties[ elem.accTypeEnumIndex ].type } elem.timeout: ${ elem.timeout } elem.interval: ${ elem.interval } to Polled Queue ${ elem.queueName }` ); - // ( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, callback, value ) - queue.addQueueEntry( false, true, elem.accessory, elem.accTypeEnumIndex, elem.interval, elem.timeout, null, null ) + // ( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, stateChangeResponseTime, callback, value ) + queue.addQueueEntry( false, true, elem.accessory, elem.accTypeEnumIndex, elem.interval, elem.timeout, elem.stateChangeResponseTime, null, null ) }); diff --git a/Cmd4PriorityPollingQueue.js b/Cmd4PriorityPollingQueue.js index 1ec6cb4..b9134f2 100644 --- a/Cmd4PriorityPollingQueue.js +++ b/Cmd4PriorityPollingQueue.js @@ -38,12 +38,12 @@ class Cmd4PriorityPollingQueue this.originalInterval = 0; this.optimalInterval = 0; } - addQueueEntry( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, callback, value ) + addQueueEntry( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, stateChangeResponseTime, callback, value ) { if ( isSet || ! isSet && !isPolled ) { // A mixture of gets and sets, all from IOS though - this.highPriorityQueue.push( { "isSet": isSet, "isPolled": isPolled, "accessory": accessory, "accTypeEnumIndex": accTypeEnumIndex, "interval": interval, "timeout": timeout, "callback": callback, "value": value } ); + this.highPriorityQueue.push( { [ constants.IS_SET_lv ]: isSet, [ constants.IS_POLLED_lv ]: isPolled, [ constants.ACCESSORY_lv ]: accessory, [ constants.ACC_TYPE_ENUM_INDEX_lv ]: accTypeEnumIndex, [ constants.INTERVAL_lv ]: interval, [ constants.TIMEOUT_lv ]: timeout, [ constants.STATE_CHANGE_RESPONSE_TIME_lv ]: stateChangeResponseTime, [ constants.CALLBACK_lv ]: callback, [ constants.VALUE_lv ]: value } ); if ( this.queueStarted == true ) { // We cant have a low priority timer going off starting the queue @@ -60,12 +60,12 @@ class Cmd4PriorityPollingQueue } else { // These are all gets from polling - this.lowPriorityQueue.push( { "isSet": isSet, "isPolled": isPolled, "accessory": accessory, "accTypeEnumIndex": accTypeEnumIndex, "interval": interval, "timeout": timeout, "callback": callback, "value": value } ); + this.lowPriorityQueue.push( { [ constants.IS_SET_lv ]: isSet, [ constants.IS_POLLED_lv ]: isPolled, [ constants.ACCESSORY_lv ]: accessory, [ constants.ACC_TYPE_ENUM_INDEX_lv ]: accTypeEnumIndex, [ constants.INTERVAL_lv ]: interval, [ constants.TIMEOUT_lv ]: timeout, [ constants.CALLBACK_lv ]: callback, [ constants.VALUE_lv ]: value } ); if ( this.currentIntervalBeingUsed == 0 ) { if ( this.queueMsg == true ) - this.log.info( `Interval being used for queue: "${ this.queueName }" is from ${ accessory.displayName } ${ CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type } interval: ${ interval }` ); + this.log.info( `Interval being used for queue: "${ this.queueName }" is from ${ accessory.displayName } ${ CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type } ${ constants.INTERVAL_lv }: ${ interval }` ); this.currentIntervalBeingUsed = interval; this.optimalInterval = interval; this.originalInterval = interval; @@ -90,7 +90,7 @@ class Cmd4PriorityPollingQueue let relatedCurrentAccTypeEnumIndex = CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].relatedCurrentAccTypeEnumIndex; if ( relatedCurrentAccTypeEnumIndex != null && settings.arrayOfPollingCharacteristics.filter( entry => entry.accessory.UUID == self.UUID && - entry.accTypeEnumIndex == relatedCurrentAccTypeEnumIndex + entry.accTypeEnumIndex == 999 ).length > 0 && isRelatedTargetCharacteristicInSameDevice( self.typeIndex, @@ -102,23 +102,29 @@ class Cmd4PriorityPollingQueue { let pollingID = Date.now( ); let relatedCharacteristic = CMD4_ACC_TYPE_ENUM.properties[ relatedCurrentAccTypeEnumIndex ].characteristic; - entry.accessory.getValue( relatedCharacteristic, function ( error, properValue, returnedPollingID ) - { - // This function should only be called once, noted by the pollingID. - if ( pollingID != returnedPollingID ) + let stateChangeResponseTime = entry.stateChangeResponseTime; + if ( stateChangeResponseTime < this.currentIntervalBeingUsed * .5 ) + stateChangeResponseTime = this.currentIntervalBeingUsed * .5; + + setTimeout(() => { + entry.accessory.getValue( relatedCharacteristic, function ( error, properValue, returnedPollingID ) { - entry.accessory.log.info("More entries for pollingID for related get"); + // This function should only be called once, noted by the pollingID. + if ( pollingID != returnedPollingID ) + { + entry.accessory.log.info("More entries for pollingID for related get"); - return; - } + return; + } - pollingID = -1; + pollingID = -1; - entry.callback( error ); + entry.callback( error ); - setTimeout( ( ) => { self.processQueue( ); }, 0); + setTimeout( ( ) => { self.processQueue( ); }, 0); - }, pollingID ); + }, pollingID ); + }, stateChangeResponseTime ); } else { entry.callback( error ); @@ -136,7 +142,7 @@ class Cmd4PriorityPollingQueue // This function should only be called once, noted by the pollingID. if ( pollingID != returnedPollingID ) { - entry.accessory.log.info(`More entries for pollingID of get error:${error} val:${properValue} returnedPollingID:${returnedPollingID}`); + entry.accessory.log.info(`More entries for pollingID of get error:${error} value:${properValue} returnedPollingID:${returnedPollingID}`); return; } diff --git a/cmd4Constants.js b/cmd4Constants.js index c26c97b..a327ede 100644 --- a/cmd4Constants.js +++ b/cmd4Constants.js @@ -1,5 +1,10 @@ "use strict"; +// Naming convention +// DEFAULT_ => Default values +// _l => Lower Case +// _lv => Lower Case Variable of same name + // Triggers which Array CMD4Accessory will be placed // Either cmd4Accessories or cmd4StandaloneAccessories exports.STANDALONE = "Standalone"; @@ -9,6 +14,7 @@ exports.COLLECTION = "Collection"; // Default intervals exports.SLOW_STATE_CHANGE_RESPONSE_TIME = 10000; // 10 seconds exports.MEDIUM_STATE_CHANGE_RESPONSE_TIME = 3000; // 3 seconds +exports.DEFAULT_STATE_CHANGE_RESPONSE_TIME = 3000; // 3 seconds exports.FAST_STATE_CHANGE_RESPONSE_TIME = 1000; // 1 second exports.DEFAULT_TIMEOUT = 60000; // 1 minute @@ -120,6 +126,19 @@ exports.VALIDVALUES = "ValidValues"; exports.ACCESS = "Access"; +// Internal list variables +exports.ACCESSORY_lv = "accessory"; +exports.CALLBACK_lv = "callback"; +exports.ACC_TYPE_ENUM_INDEX_lv = "accTypeEnumIndex"; +exports.INTERVAL_lv = "interval"; +exports.IS_SET_lv = "isSet"; +exports.IS_POLLED_lv = "isPolled"; +exports.QUEUE_lv = "queue"; +exports.QUEUE_NAME_lv = "queueName"; +exports.RC_lv = "rc"; +exports.STATE_CHANGE_RESPONSE_TIME_lv = "stateChangeResponseTime"; +exports.TIMEOUT_lv = "timeout"; +exports.VALUE_lv = "value"; exports.ERROR_TIMER_EXPIRED = -151; exports.ERROR_CMD_FAILED_REPLY = -152; diff --git a/test/Cmd4AccessorySetValue.js b/test/Cmd4AccessorySetValue.js index 3d8bf65..7fccbdf 100644 --- a/test/Cmd4AccessorySetValue.js +++ b/test/Cmd4AccessorySetValue.js @@ -257,7 +257,7 @@ describe( "Testing Cmd4Accessory", function( ) new Cmd4Accessory( log, TVConfig, _api, [ ], null ); - let expectedPublishedOutput = `Televisions should be Platform Accessories with "publishExternally": true,`; + let expectedPublishedOutput = `Televisions should be Platform Accessories with "PublishExternally": true,`; assert.include( log.errBuf, expectedPublishedOutput, `Cmd4Accessory output expected: ${ expectedPublishedOutput } received: ${ log.logBuf }` ); assert.equal( 0, log.logLineCount, ` Cmd4Accessory logged lines than one: ${ log.logBuf }` ); diff --git a/test/Cmd4Platform.js b/test/Cmd4Platform.js index b3a945f..860cf32 100644 --- a/test/Cmd4Platform.js +++ b/test/Cmd4Platform.js @@ -165,7 +165,7 @@ describe('Testing Cmd4Platform Cmd4Mode gets passed to accessories', ( ) => cmd4Platform.discoverDevices( ); - assert.equal( cmd4Platform.createdCmd4Accessories.length, 1, ` Cmd4Platform did not create the cmd4Accessory }` ); + assert.equal( cmd4Platform.createdCmd4Accessories.length, 1, ` Cmd4Platform did not create the cmd4Accessory` ); let expectedOutput1 = `Adding new platformAccessory: My_Door`; let expectedOutput2 = `35mConfiguring platformAccessory: \u001b[39mMy_Door`; @@ -315,4 +315,121 @@ describe('Testing Cmd4Platform Cmd4Mode gets passed to accessories', ( ) => done( ); }); + + it('Test if interval, timeout, stateChangeResponseTime are used from the platform', ( done ) => + { + let platformConfig = + { + Cmd4_Mode: "Polled", + timeout: 12345, + interval: 12, + stateChangeResponseTime: 18, + accessories: [ + { + Name: "My_Door", + DisplayName: "My_Door", + StatusMsg: true, + Type: "Door", + QueueMsg: true, + QueueStatMsgInterval: 1400, + CurrentPosition: 0, + TargetPosition: 0, + PositionState: 0, + polling: [ { "characteristic": "CurrentPosition", "queue": "A" }, + { "characteristic": "TargetPosition", "queue": "A" }, + { "characteristic": "PositionState", "queue": "A" } + ], + State_cmd: "node ./Extras/Cmd4Scripts/Examples/AnyDevice" + } + ] + } + + assert.equal( settings.arrayOfPollingCharacteristics.length, 0, `Incorrect number of Initial polling characteristics` ); + + this.log = new Logger( ); + this.log.setBufferEnabled( ); + this.log.setOutputEnabled( false ); + this.log.setDebugEnabled( false ); + + let cmd4Platform = new Cmd4Platform( this.log, platformConfig, _api ); + + cmd4Platform.discoverDevices( ); + + assert.equal( cmd4Platform.createdCmd4Accessories.length, 1, ` Cmd4Platform did not create the cmd4Accessory` ); + + let cmd4Accessory = cmd4Platform.createdCmd4Accessories[0]; + + assert.equal( settings.arrayOfPollingCharacteristics.length, 3, `Incorret number of polling characteristics` ); + + assert.equal( cmd4Accessory.timeout, 12345, `Timeout was not passed down to accessory` ); + assert.equal( cmd4Accessory.interval, 12000, `Interval was not passed down to accessory` ); + assert.equal( cmd4Accessory.stateChangeResponseTime, 18000, `stateChangeResponseTime was not passed down to accessory` ); + + settings.arrayOfPollingCharacteristics.forEach( ( entry ) => + { + assert.equal( entry.timeout, 12345, `Timeout was not passed down to polling entry` ); + assert.equal( entry.interval, 12000, `Interval was not passed down to polling entry` ); + assert.equal( entry.stateChangeResponseTime, 18000, `stateChangeResponseTime was not passed down to polling entry` ); + }); + + done( ); + }); + + it('Test stateChangeResponseTime are used from the accessory definition', ( done ) => + { + let platformConfig = + { + Cmd4_Mode: "Polled", + timeout: 12345, + interval: 12, + accessories: [ + { + Name: "My_Door", + DisplayName: "My_Door", + StatusMsg: true, + Type: "Door", + QueueMsg: true, + QueueStatMsgInterval: 1400, + CurrentPosition: 0, + TargetPosition: 0, + PositionState: 0, + polling: [ { "characteristic": "CurrentPosition", "queue": "A" }, + { "characteristic": "TargetPosition", "queue": "A" }, + { "characteristic": "PositionState", "queue": "A" } + ], + State_cmd: "node ./Extras/Cmd4Scripts/Examples/AnyDevice" + } + ] + } + + assert.equal( settings.arrayOfPollingCharacteristics.length, 0, `Incorrect number of Initial polling characteristics` ); + + this.log = new Logger( ); + this.log.setBufferEnabled( ); + this.log.setOutputEnabled( false ); + this.log.setDebugEnabled( false ); + + let cmd4Platform = new Cmd4Platform( this.log, platformConfig, _api ); + + cmd4Platform.discoverDevices( ); + + assert.equal( cmd4Platform.createdCmd4Accessories.length, 1, ` Cmd4Platform did not create the cmd4Accessory` ); + + let cmd4Accessory = cmd4Platform.createdCmd4Accessories[0]; + + assert.equal( settings.arrayOfPollingCharacteristics.length, 3, `Incorret number of polling characteristics` ); + + assert.equal( cmd4Accessory.timeout, 12345, `Timeout was not passed down to accessory` ); + assert.equal( cmd4Accessory.interval, 12000, `Interval was not passed down to accessory` ); + assert.equal( cmd4Accessory.stateChangeResponseTime, constants.MEDIUM_STATE_CHANGE_RESPONSE_TIME, `stateChangeResponseTime was not passed from CMD4_DEVICE_TYPE_ENUM` ); + + settings.arrayOfPollingCharacteristics.forEach( ( entry ) => + { + assert.equal( entry.timeout, 12345, `Timeout was not passed down to polling entry` ); + assert.equal( entry.interval, 12000, `Interval was not passed down to polling entry` ); + assert.equal( entry.stateChangeResponseTime, constants.MEDIUM_STATE_CHANGE_RESPONSE_TIME, `stateChangeResponseTime was not passed from CMD4_DEVICE_TYPE_ENUM` ); + }); + + done( ); + }); }); diff --git a/test/Cmd4PriorityPollingQueue.js b/test/Cmd4PriorityPollingQueue.js index 86d421b..d573d3e 100644 --- a/test/Cmd4PriorityPollingQueue.js +++ b/test/Cmd4PriorityPollingQueue.js @@ -134,7 +134,7 @@ describe('Testing Cmd4PriorityPollingQueue polling', ( ) => assert.isFunction( cmd4PriorityPollingQueue.addQueueEntry, `.addQueueEntry is not a function` ); // ( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, callback, value ) - cmd4PriorityPollingQueue.addQueueEntry( true, false, cmd4Accessory, CMD4_ACC_TYPE_ENUM.On, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, dummyCallback, value ); + cmd4PriorityPollingQueue.addQueueEntry( true, false, cmd4Accessory, CMD4_ACC_TYPE_ENUM.On, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME, dummyCallback, value ); assert.equal( cmd4PriorityPollingQueue.highPriorityQueue.length, 1, `Set not added to high prority queue` ); @@ -149,6 +149,9 @@ describe('Testing Cmd4PriorityPollingQueue polling', ( ) => assert.equal( entry.value, value, `Wrong value for Set added to queue` ); assert.equal( entry.accTypeEnumIndex, CMD4_ACC_TYPE_ENUM.On, `On was not stored as a set` ); + assert.equal( entry.interval, constants.DEFAULT_INTERVAL, `interval was not stored` ); + assert.equal( entry.timeout, constants.DEFAULT_TIMEOUT, `timeout was not stored` ); + assert.equal( entry.stateChangeResponseTime, constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME, `stateChangeResponseTime was not stored` ); assert.equal( entry.callback, dummyCallback, `callback was not stored as a set` ); }); @@ -184,7 +187,7 @@ describe('Testing Cmd4PriorityPollingQueue polling', ( ) => assert.isFunction( cmd4PriorityPollingQueue.addQueueEntry, `.addQueueEntry is not a function` ); // ( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, callback, value ) - cmd4PriorityPollingQueue.addQueueEntry( false, false, cmd4Accessory, CMD4_ACC_TYPE_ENUM.On, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, dummyCallback, 1 ); + cmd4PriorityPollingQueue.addQueueEntry( false, false, cmd4Accessory, CMD4_ACC_TYPE_ENUM.On, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME, dummyCallback, 1 ); assert.equal( cmd4PriorityPollingQueue.highPriorityQueue.length, 1, `IOS Get not added to high prority queue` ); @@ -232,7 +235,7 @@ describe('Testing Cmd4PriorityPollingQueue polling', ( ) => assert.isFunction( cmd4PriorityPollingQueue.addQueueEntry, `.addQueueEntry is not a function` ); // ( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, callback, value ) - cmd4PriorityPollingQueue.addQueueEntry( false, true, cmd4Accessory, CMD4_ACC_TYPE_ENUM.On, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, dummyCallback, null ); + cmd4PriorityPollingQueue.addQueueEntry( false, true, cmd4Accessory, CMD4_ACC_TYPE_ENUM.On, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME, dummyCallback, null ); assert.equal( cmd4PriorityPollingQueue.lowPriorityQueue.length, 1, `Polled Get added to low prority queue` ); @@ -276,8 +279,8 @@ describe('Testing Cmd4PriorityPollingQueue polling', ( ) => let cmd4PriorityPollingQueue = new Cmd4PriorityPollingQueue( this.log, queueName ); // ( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, callback, value ) - cmd4PriorityPollingQueue.addQueueEntry( false, true, cmd4Accessory, CMD4_ACC_TYPE_ENUM.On, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, dummyCallback, null ); - cmd4PriorityPollingQueue.addQueueEntry( false, true, cmd4Accessory, CMD4_ACC_TYPE_ENUM.Active, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, dummyCallback, null ); + cmd4PriorityPollingQueue.addQueueEntry( false, true, cmd4Accessory, CMD4_ACC_TYPE_ENUM.On, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME, dummyCallback, null ); + cmd4PriorityPollingQueue.addQueueEntry( false, true, cmd4Accessory, CMD4_ACC_TYPE_ENUM.Active, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME, dummyCallback, null ); assert.equal( cmd4PriorityPollingQueue.lowPriorityQueue.length, 2, `Polled Get added to low prority queue` ); @@ -338,8 +341,8 @@ describe('Testing Cmd4PriorityPollingQueue polling', ( ) => let cmd4PriorityPollingQueue = new Cmd4PriorityPollingQueue( this.log, queueName ); // ( isSet, isPolled, accessory, accTypeEnumIndex, interval, timeout, callback, value ) - cmd4PriorityPollingQueue.addQueueEntry( false, false, cmd4Accessory, CMD4_ACC_TYPE_ENUM.On, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, dummyCallback, null ); - cmd4PriorityPollingQueue.addQueueEntry( false, false, cmd4Accessory, CMD4_ACC_TYPE_ENUM.Active, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, dummyCallback, null ); + cmd4PriorityPollingQueue.addQueueEntry( false, false, cmd4Accessory, CMD4_ACC_TYPE_ENUM.On, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME, dummyCallback, null ); + cmd4PriorityPollingQueue.addQueueEntry( false, false, cmd4Accessory, CMD4_ACC_TYPE_ENUM.Active, constants.DEFAULT_INTERVAL, constants.DEFAULT_TIMEOUT, constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME, dummyCallback, null ); assert.equal( cmd4PriorityPollingQueue.highPriorityQueue.length, 2, `IOS Get added to high prority queue` );