Skip to content

Commit

Permalink
fix: For burst feat, Dont confuse interval and burstInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
ztalbot2000 committed May 21, 2021
1 parent d1296b1 commit 59c6490
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
26 changes: 15 additions & 11 deletions Cmd4PriorityPollingQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ let LOW_PRIORITY_GET = 2;

class Cmd4PriorityPollingQueue
{
constructor( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE, burstGroupSize = constants.DEFAULT_BURSTGROUP_SIZE, interval = constants.DEFAULT_BURST_INTERVAL )
constructor( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE, burstGroupSize = constants.DEFAULT_BURSTGROUP_SIZE, burstInterval = constants.DEFAULT_BURST_INTERVAL )
{
this.log = log;
this.queueName = queueName;
this.queueType = queueType;
this.burstGroupSize = burstGroupSize;
this.burstInterval = interval;
this.burstInterval = burstInterval;
this.queueStarted = false;
this.highPriorityQueue = [ ];
this.lowPriorityQueue = [ ];
Expand Down Expand Up @@ -102,7 +102,11 @@ class Cmd4PriorityPollingQueue

if ( queue.queueMsg == true )
this.log.info( `Interval being used for queue: "${ queue.queueName }" is from ${ accessory.displayName } ${ CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type } ${ constants.INTERVAL_lv }: ${ interval }` );
queue.variablePollingTimer.iv = interval;

// Do not overide the burstInterval
if ( queue.burstGroupSize == 0 )
queue.variablePollingTimer.iv = interval;

queue.optimalInterval = interval;
queue.originalInterval = interval;
queue.queueStatMsgInterval = accessory.queueStatMsgInterval;
Expand Down Expand Up @@ -629,14 +633,14 @@ var queueExists = function( queueName )
return settings.listOfCreatedPriorityQueues[ queueName ];
}

var addQueue = function( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE, burstGroupSize = constants.DEFAULT_BURST_GROUP_SIZE, interval = constants.DEFAULT_BURST_INTERVAL )
var addQueue = function( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE, burstGroupSize = constants.DEFAULT_BURST_GROUP_SIZE, burstInterval = constants.DEFAULT_BURST_INTERVAL )
{
let queue = queueExists( queueName );
if ( queue != undefined )
return queue;

log.info( `Creating new Priority Polled Queue "${ queueName }" with QueueType of: "${ queueType }" burstGroupSize: ${ burstGroupSize } interval: ${ interval }` );
queue = new Cmd4PriorityPollingQueue( log, queueName, queueType, burstGroupSize, interval );
log.info( `Creating new Priority Polled Queue "${ queueName }" with QueueType of: "${ queueType }" burstGroupSize: ${ burstGroupSize } interval: ${ burstInterval }` );
queue = new Cmd4PriorityPollingQueue( log, queueName, queueType, burstGroupSize, burstInterval );
settings.listOfCreatedPriorityQueues[ queueName ] = queue;

return queue;
Expand All @@ -655,7 +659,7 @@ var parseAddQueueTypes = function ( log, entrys )
let queueName = constants.DEFAULT_QUEUE_NAME;
let queueType = constants.DEFAULT_QUEUE_TYPE;
let burstGroupSize = constants.DEFAULT_BURST_GROUP_SIZE;
let interval = constants.DEFAULT_BURST_INTERVAL;
let burstInterval = constants.DEFAULT_BURST_INTERVAL;

for ( let key in entry )
{
Expand Down Expand Up @@ -684,15 +688,15 @@ var parseAddQueueTypes = function ( log, entrys )
queueType = value;

break;
case constants.INTERVAL:
case constants.BURST_INTERVAL:
if ( parseInt( value, 10 ) < 5 )
{
log.error( chalk.red( `Error: Burst interval of ( ${ value }s /) to short at index: ${ entryIndex }. Expected: number >= 5s` ) );
process.exit( 448 ) ;
}

// Intervals are in seconds
interval = parseInt( value, 10 ) * 1000;
burstInterval = parseInt( value, 10 ) * 1000;

break;
case constants.BURST_GROUP_SIZE:
Expand Down Expand Up @@ -723,8 +727,8 @@ var parseAddQueueTypes = function ( log, entrys )
log.error( chalk.red( `Error: Queue Type: "${ constants.QUEUETYPE_SEQUENTIAL }" and "${ constants.BURST_GROUP_SIZE }" are incompatible at index ${ entryIndex }` ) );
process.exit( 448 ) ;
}
log.debug( "calling addQueue: %s type: %s burstGroupSize: %s interval: %s", queueName, queueType, burstGroupSize, interval);
addQueue( log, queueName, queueType, burstGroupSize, interval );
log.debug( `calling addQueue: ${ queueName } type: ${ queueType} burstGroupSize: ${ burstGroupSize } burstInterval: ${ burstInterval }` );
addQueue( log, queueName, queueType, burstGroupSize, burstInterval );
});
}

Expand Down
1 change: 1 addition & 0 deletions cmd4Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ exports.QUEUETYPES = "QueueTypes";
exports.QUEUETYPE_SEQUENTIAL = "Sequential";
exports.QUEUETYPE_WORM = "WoRm";
exports.BURST_GROUP_SIZE = "BurstGroupSize";
exports.BURST_INTERVAL = "BurstInterval";

//exports.STATUSMSG_l = "statusMsg";

Expand Down
4 changes: 2 additions & 2 deletions test/Cmd4PriorityPollingQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ describe('Testing Cmd4PriorityPollingQueue burst', ( ) =>
Cmd4_Mode: "Polled",
On: 0,
Brightness: 100,
QueueTypes: [{ queue: "A", queueType: "WoRm", BurstGroupSize: 1, Interval: 5 }],
QueueTypes: [{ queue: "A", queueType: "WoRm", BurstGroupSize: 1, burstInterval: 5 }],
Queue: "A",
polling: [ { "characteristic": "on" },
{ "characteristic": "brightness" }
Expand Down Expand Up @@ -925,7 +925,7 @@ describe('Testing Cmd4PriorityPollingQueue sanity correction', ( ) =>
Cmd4_Mode: "Polled",
On: 0,
Brightness: 100,
QueueTypes: [{ queue: "A", queueType: "WoRm", BurstGroupSize: 1, Interval: 5 }],
QueueTypes: [{ queue: "A", queueType: "WoRm", BurstGroupSize: 1, burstInterval: 5 }],
Queue: "A",
polling: [ { "characteristic": "on" },
{ "characteristic": "brightness" }
Expand Down

0 comments on commit 59c6490

Please sign in to comment.