@@ -37,10 +37,6 @@ export default class HubitatClient {
3737 batchSize : 10 ,
3838 batchDelay : 25 ,
3939 maxBatchDelay : 100 ,
40- isProcessing : false ,
41- totalQueued : 0 ,
42- totalProcessed : 0 ,
43- totalBatches : 0 ,
4440 } ;
4541
4642 // Retry configuration
@@ -155,32 +151,14 @@ export default class HubitatClient {
155151 }
156152
157153 async processBatch ( ) {
158- // Prevent concurrent batch processing
159- if ( this . commandState . isProcessing ) {
160- this . logManager . logDebug ( "Batch processing already in progress, skipping" ) ;
161- return ;
162- }
163-
164- if ( ! this . commandState . queue . length ) {
165- this . commandState . batchTimer = null ;
166- return ;
167- }
168-
169- // Set processing flag and clear timer
170- this . commandState . isProcessing = true ;
171- this . commandState . batchTimer = null ;
154+ if ( ! this . commandState . queue . length ) return ;
172155
173156 const commands = this . commandState . queue . splice ( 0 , this . commandState . batchSize ) ;
157+ this . commandState . batchTimer = null ;
174158 const startTime = Date . now ( ) ;
175159 let success = false ;
176160 let error = null ;
177161
178- // Update statistics
179- this . commandState . totalBatches ++ ;
180- this . commandState . totalProcessed += commands . length ;
181-
182- this . logManager . logDebug ( `Processing batch of ${ commands . length } commands (${ this . commandState . queue . length } remaining in queue) | Total batches: ${ this . commandState . totalBatches } , Total processed: ${ this . commandState . totalProcessed } ` ) ;
183-
184162 try {
185163 const formattedCommands = commands . map ( ( cmd ) => ( {
186164 deviceId : cmd . devData . deviceid ,
@@ -199,24 +177,15 @@ export default class HubitatClient {
199177 timeout : 5000 ,
200178 } ) ;
201179 success = true ;
202- this . logManager . logDebug ( `Successfully processed batch of ${ commands . length } commands` ) ;
203180 } catch ( err ) {
204181 success = false ;
205182 error = err . message ;
206183 this . handleError ( "processBatch" , err ) ;
207- this . logManager . logWarn ( `Batch processing failed, falling back to individual commands for ${ commands . length } commands` ) ;
208-
209184 // Fall back to individual commands - metrics will be recorded in sendSingleCommand
210185 for ( const cmd of commands ) {
211- try {
212- await this . sendSingleCommand ( cmd . devData , cmd . command , cmd . params ) ;
213- } catch ( singleErr ) {
214- this . logManager . logError ( `Failed to send individual command ${ cmd . command } to device ${ cmd . devData . name } :` , singleErr ) ;
215- }
186+ await this . sendSingleCommand ( cmd . devData , cmd . command , cmd . params ) ;
216187 }
217- } finally {
218- // Always clear processing flag
219- this . commandState . isProcessing = false ;
188+ return ; // Skip metrics recording as individual commands will handle it
220189 }
221190
222191 // Record batch command metrics only if successful
@@ -239,7 +208,7 @@ export default class HubitatClient {
239208 }
240209
241210 // Process remaining queue if any
242- if ( this . commandState . queue . length > 0 ) {
211+ if ( this . commandState . queue . length ) {
243212 this . scheduleBatchProcessing ( ) ;
244213 }
245214 }
@@ -297,19 +266,12 @@ export default class HubitatClient {
297266 // Add command to batch queue
298267 this . commandState . queue . push ( { devData, command : cmd , params } ) ;
299268 this . commandState . lastExecutions . set ( cmd , Date . now ( ) ) ;
300- this . commandState . totalQueued ++ ;
301-
302- this . logManager . logDebug ( `Command queued. Queue size: ${ this . commandState . queue . length } , Processing: ${ this . commandState . isProcessing } , Total queued: ${ this . commandState . totalQueued } ` ) ;
303269
304270 // If queue reaches batch size, process immediately
305271 if ( this . commandState . queue . length >= this . commandState . batchSize ) {
306- this . logManager . logDebug ( `Queue reached batch size (${ this . commandState . batchSize } ), processing immediately` ) ;
307272 await this . processBatch ( ) ;
308273 } else {
309- // Only schedule if not already processing
310- if ( ! this . commandState . isProcessing ) {
311- this . scheduleBatchProcessing ( ) ;
312- }
274+ this . scheduleBatchProcessing ( ) ;
313275 }
314276
315277 return true ;
@@ -320,23 +282,9 @@ export default class HubitatClient {
320282 }
321283
322284 scheduleBatchProcessing ( ) {
323- // Don't schedule if already processing or timer exists
324- if ( this . commandState . isProcessing || this . commandState . batchTimer ) {
325- return ;
326- }
327-
328- // Don't schedule if queue is empty
329- if ( this . commandState . queue . length === 0 ) {
330- return ;
331- }
285+ if ( this . commandState . batchTimer ) return ;
332286
333- this . commandState . batchTimer = setTimeout (
334- ( ) => {
335- this . commandState . batchTimer = null ;
336- this . processBatch ( ) ;
337- } ,
338- Math . min ( this . commandState . batchDelay , this . commandState . maxBatchDelay ) ,
339- ) ;
287+ this . commandState . batchTimer = setTimeout ( ( ) => this . processBatch ( ) , Math . min ( this . commandState . batchDelay , this . commandState . maxBatchDelay ) ) ;
340288 }
341289
342290 handleError ( source , error ) {
@@ -437,19 +385,6 @@ export default class HubitatClient {
437385 } ;
438386 }
439387
440- getCommandQueueStats ( ) {
441- return {
442- queueSize : this . commandState . queue . length ,
443- isProcessing : this . commandState . isProcessing ,
444- batchSize : this . commandState . batchSize ,
445- batchDelay : this . commandState . batchDelay ,
446- totalQueued : this . commandState . totalQueued ,
447- totalProcessed : this . commandState . totalProcessed ,
448- totalBatches : this . commandState . totalBatches ,
449- hasTimer : ! ! this . commandState . batchTimer ,
450- } ;
451- }
452-
453388 /**
454389 * Clean up idle connections
455390 */
@@ -648,7 +583,6 @@ export default class HubitatClient {
648583 // Clear command batching timers
649584 if ( this . commandState . batchTimer ) {
650585 clearTimeout ( this . commandState . batchTimer ) ;
651- this . commandState . batchTimer = null ;
652586 }
653587 if ( this . attributeBatchTimer ) {
654588 clearTimeout ( this . attributeBatchTimer ) ;
@@ -666,7 +600,6 @@ export default class HubitatClient {
666600 this . commandState . queue = [ ] ;
667601 this . commandState . timers . clear ( ) ;
668602 this . commandState . lastExecutions . clear ( ) ;
669- this . commandState . isProcessing = false ;
670603 this . attributeUpdateQueue . clear ( ) ;
671604 this . appEvts . removeAllListeners ( ) ;
672605
0 commit comments