Skip to content

Commit

Permalink
feat: v5.0 Simplification, Remove unused QUEUEMSG
Browse files Browse the repository at this point in the history
  • Loading branch information
ztalbot2000 committed Aug 1, 2021
1 parent 120f2a9 commit f25dac8
Show file tree
Hide file tree
Showing 6 changed files with 1,037 additions and 421 deletions.
22 changes: 12 additions & 10 deletions Cmd4Accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ class Cmd4Accessory
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;
this.queueMsg = ( parentInfo && parentInfo.queueMsg ) ? parentInfo.queueMsg : constants.DEFAULT_QUEUEMSG;
this.queueStatMsgInterval = ( parentInfo && parentInfo.queueStatMsgInterval ) ? parentInfo.queueStatMsgInterval : constants.DEFAULT_QUEUE_STAT_MSG_INTERVAL;
// Everything that needs to talk to the device now goes through the queue
this.queue = null;

Expand Down Expand Up @@ -1617,17 +1615,17 @@ class Cmd4Accessory

break;
case constants.QUEUE_STAT_MSG_INTERVAL:
this.queueStatMsgInterval = value;

// No longer applicable

break;
case constants.QUEUEMSG:
this.queueMsg = value;

// No longer applicable

break;
case constants.QUEUETYPES:
parseAddQueueTypes( this.log, value,
{ [ constants.QUEUE_STAT_MSG_INTERVAL_lv ]: this.queueStatMsgInterval,
[ constants.QUEUEMSG_lv ]: this.queueMsg } );
parseAddQueueTypes( this.log, value );

break;
case constants.QUEUE:
Expand Down Expand Up @@ -2008,7 +2006,7 @@ class Cmd4Accessory
// process.exit( 208 );
}

this.queue = addQueue( this.log, value, constants.QUEUETYPE_WORM, this.interval, this.queueMsg, this.queueStatMsgInterval );
this.queue = addQueue( this.log, value, constants.QUEUETYPE_WORM );

break;
}
Expand Down Expand Up @@ -2060,7 +2058,9 @@ class Cmd4Accessory

// Everything now goes through the queue
if ( this.queue == null )
this.queue = addQueue( this.log, "Q:" + this.displayName, constants.QUEUETYPE_STANDARD, this.interval, this.queueMsg, this.queueStatMsgInterval );
{
this.queue = addQueue( this.log, "Q:" + this.displayName, constants.QUEUETYPE_STANDARD );
}

if ( cmd4Dbg ) this.log.debug( `Setting up accessory: ${ accessory.displayName } for polling of: ${ characteristicString } timeout: ${ timeout } interval: ${ interval } queueName: "${ this.queue.queueName }"` );

Expand All @@ -2086,7 +2086,9 @@ class Cmd4Accessory
// This list is also used to determine if the related characteristic should be set
// which happens in the Demo mode without polling.
if ( this.queue == null )
this.queue = addQueue( this.log, "Q:" + this.displayName, constants.QUEUETYPE_STANDARD, this.interval, this.queueMsg, this.queueStatMsgInterval );
{
this.queue = addQueue( this.log, "Q:" + this.displayName, constants.QUEUETYPE_STANDARD );
}

// Make sure the defined characteristics will be polled
CMD4_DEVICE_TYPE_ENUM.properties[ accessory.typeIndex ].defaultPollingCharacteristics.forEach( defaultPollingAccTypeEnumIndex =>
Expand Down
14 changes: 5 additions & 9 deletions Cmd4Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ class Cmd4Platform
this.outputConstants = constants.DEFAULT_OUTPUTCONSTANTS;
this.statusMsg = constants.DEFAULT_STATUSMSG;

// Every X polls, output the queue status information.
this.queueStatMsgInterval = constants.DEFAULT_QUEUE_STAT_MSG_INTERVAL;
this.queueMsg = constants.DEFAULT_QUEUEMSG;

// Track the polling timers only so that unit testing can cancel them.
this.pollingTimers = [ ];

Expand Down Expand Up @@ -248,17 +244,17 @@ class Cmd4Platform

break;
case constants.QUEUE_STAT_MSG_INTERVAL:
this.queueStatMsgInterval = value;

// No longer applicable

break;
case constants.QUEUEMSG:
this.queueMsg = value;

// No longer applicable

break;
case constants.QUEUETYPES:
parseAddQueueTypes( this.log, value,
{ [ constants.QUEUE_STAT_MSG_INTERVAL_lv ]: this.queueStatMsgInterval,
[ constants.QUEUEMSG_lv ]: this.queueMsg } );
parseAddQueueTypes( this.log, value );

break;
case constants.CMD4_MODE:
Expand Down
38 changes: 11 additions & 27 deletions Cmd4PriorityPollingQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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 )
constructor( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE )
{
this.log = log;

Expand All @@ -42,8 +42,6 @@ class Cmd4PriorityPollingQueue

this.queueName = queueName;
this.queueType = queueType;
this.queueMsg = queueMsg;
this.queueStatMsgInterval = queueStatMsgInterval;
this.queueStarted = false;
this.highPriorityQueue = [ ];
this.lowPriorityQueue = [ ];
Expand Down Expand Up @@ -833,24 +831,20 @@ class Cmd4PriorityPollingQueue
switch ( queueType )
{
case constants.QUEUETYPE_SEQUENTIAL:
this.log.debug("AAAAAASetting to SEQUENTIAL QUEUE");
this.processQueueFunc = this.processSequentialQueue;
break;
case constants.QUEUETYPE_WORM:
this.log.debug("AAAAAASetting to WORM QUEUE");
this.processQueueFunc = this.processWormQueue;
// When not in debug mode, do not echo errors for the WoRm queue
// as errors are handled through retries.
if ( ! cmd4Dbg )
this.echoE = false;
break;
case constants.QUEUETYPE_STANDARD:
this.log.debug("AAAAAASetting to PASSTHRU QUEUE");
// only polled entries go straight through the queue
this.processQueueFunc = this.processPassThruQueue;
break;
case constants.QUEUETYPE_PASSTHRU:
this.log.debug("AAAAAASetting to PASSTHRU QUEUE");
// entries go straight through the queue
this.processQueueFunc = this.processPassThruQueue;
break;
Expand All @@ -865,15 +859,15 @@ var queueExists = function( queueName )
return settings.listOfCreatedPriorityQueues[ queueName ];
}

var addQueue = function( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE, queueInterval = constants.DEFAULT_QUEUE_INTERVAL, queueMsg = constants.DEFAULT_QUEUEMSG, queueStatMsgInterval = constants.DEFAULT_QUEUE_STAT_MSG_INTERVAL )
var addQueue = function( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE )
{
let queue = queueExists( queueName );
if ( queue != undefined )
return queue;

log.debug( `Creating new Priority Polled Queue "${ queueName }" with QueueType of: "${ queueType }" QueueInterval: ${ queueInterval } QueueMsg: ${ queueMsg } QueueStatMsgInterval: ${ queueStatMsgInterval }` );
log.debug( `Creating new Priority Polled Queue "${ queueName }" with QueueType of: "${ queueType }"` );

queue = new Cmd4PriorityPollingQueue( log, queueName, queueType, queueInterval, queueMsg, queueStatMsgInterval );
queue = new Cmd4PriorityPollingQueue( log, queueName, queueType );
settings.listOfCreatedPriorityQueues[ queueName ] = queue;

return queue;
Expand All @@ -882,7 +876,7 @@ var addQueue = function( log, queueName, queueType = constants.DEFAULT_QUEUE_TYP



var parseAddQueueTypes = function ( log, entrys, options )
var parseAddQueueTypes = function ( log, entrys )
{
if ( trueTypeOf( entrys ) != Array )
{
Expand All @@ -893,8 +887,6 @@ var parseAddQueueTypes = function ( log, entrys, options )
{
let queueName = null;
let queueType = constants.DEFAULT_QUEUE_TYPE;
let queueMsg = options.queueMsg;
let queueStatMsgInterval = options.queueStatMsgInterval;

for ( let key in entry )
{
Expand Down Expand Up @@ -929,21 +921,13 @@ var parseAddQueueTypes = function ( log, entrys, options )

break;
case constants.QUEUEMSG:
if ( typeof value != "boolean" )
{
log.error( chalk.red( `Error: ${ constants.QUEUEMSG }: ${ value } is invalid at index: ${ entryIndex }. Expected: true/false` ) );
process.exit( 448 ) ;
}
queueMsg = value;

// No Longer applicable

break;
case constants.QUEUE_STAT_MSG_INTERVAL:
if ( typeof value != "number" && value < 5 )
{
log.error( chalk.red( `Error: ${ constants.QUEUE_STAT_MSG_INTERVAL }: ${ value } is not a valid number index: ${ entryIndex }. Expected: number >= 5` ) );
process.exit( 448 );
}
queueStatMsgInterval = value;

// No Longer applicable

break;
default:
Expand All @@ -958,8 +942,8 @@ var parseAddQueueTypes = function ( log, entrys, options )
log.error( chalk.red( `Error: "${ constants.QUEUE }" not provided at index ${ entryIndex }` ) );
process.exit( 448 ) ;
}
if ( cmd4Dbg ) log.debug( `calling addQueue: ${ queueName } type: ${ queueType } queueMsg: ${ queueMsg } queueStatMsgInterval: ${ queueStatMsgInterval }` );
addQueue( log, queueName, queueType, queueMsg, queueStatMsgInterval );
if ( cmd4Dbg ) log.debug( `calling addQueue: ${ queueName } type: ${ queueType }` );
addQueue( log, queueName, queueType );
} );
}

Expand Down
2 changes: 0 additions & 2 deletions cmd4Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ exports.INTERVAL_lv = "interval";
exports.IS_SET_lv = "isSet";
exports.QUEUE_NAME_lv = "queueName";
exports.QUEUE_GET_IS_UPDATE_lv = "queueGetIsUpdate";
exports.QUEUEMSG_lv = "queueMsg";
exports.QUEUE_STAT_MSG_INTERVAL_lv = "queueStatMsgInterval";
exports.RC_lv = "rc";
exports.STATE_CHANGE_RESPONSE_TIME_lv = "stateChangeResponseTime";
exports.TIMEOUT_lv = "timeout";
Expand Down
61 changes: 1 addition & 60 deletions test/Cmd4Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,64 +219,7 @@ describe('Testing Cmd4Platform Cmd4Mode gets passed to accessories', ( ) =>
done( );
});

it('Test if QueueMsg, QueueStatMsgInterval gets passed down to the accessory', ( done ) =>
{
let platformConfig =
{
QueueMsg: true,
QueueStatMsgInterval: 1200,
accessories: [
{
Name: "My_Door",
DisplayName: "My_Door",
StatusMsg: true,
Type: "Door",
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"
} ]
}

let log = new Logger( );
log.setBufferEnabled( );
log.setOutputEnabled( false );
log.setDebugEnabled( false );


let cmd4Platform = new Cmd4Platform( log, platformConfig, _api );

cmd4Platform.discoverDevices( );

assert.equal( cmd4Platform.createdCmd4Accessories.length, 1, ` Cmd4Platform did not create the cmd4Accessory` );

let cmd4Accessory = cmd4Platform.createdCmd4Accessories[0];

assert.equal( cmd4Accessory.queueMsg, true, ` Created accessory has incorrect QueueMsg` );
assert.equal( cmd4Accessory.queueStatMsgInterval, 1200, ` Created accessory has incorrect QueueStatMsgInterval` );

cmd4Platform.startPolling( 5000, 5000 );

cmd4Platform.pollingTimers.forEach( ( timer ) =>
{
clearTimeout( timer );
});

let numberOfQueues = Object.keys( settings.listOfCreatedPriorityQueues ).length;

assert.equal( numberOfQueues, 1, `Incorrect number of polling queues` );

let queue = settings.listOfCreatedPriorityQueues[ "A" ];

expect( queue ).to.be.a.instanceOf( Cmd4PriorityPollingQueue, "queue is not an instance of Cmd4PriorityPollingQueue" );

done( );
});

it('Test if OutputConstants, QueueMsg, QueueStatMsgInterval are used from the accessory', ( done ) =>
it('Test if OutputConstants are used from the accessory', ( done ) =>
{
let platformConfig =
{
Expand Down Expand Up @@ -316,8 +259,6 @@ describe('Testing Cmd4Platform Cmd4Mode gets passed to accessories', ( ) =>

let cmd4Accessory = cmd4Platform.createdCmd4Accessories[0];

assert.equal( cmd4Accessory.queueMsg, true, ` Created accessory has incorrect QueueMsg` );
assert.equal( cmd4Accessory.queueStatMsgInterval, 1400, ` Created accessory has incorrect QueueStatMsgInterval` );
assert.equal( cmd4Accessory.outputConstants, true, ` Created Accessory has incorrect OutputConstants` );

done( );
Expand Down
Loading

0 comments on commit f25dac8

Please sign in to comment.