@@ -249,7 +249,7 @@ export class tasmotaPlatform implements DynamicPlatformPlugin {
249249 if ( this . discoveryTopicMap [ topic ] ) {
250250 const existingAccessory = this . accessories . find ( accessory => accessory . UUID === this . discoveryTopicMap [ topic ] . uuid ) ;
251251 if ( existingAccessory ) {
252- // debug('Remove', this.discoveryTopicMap[topic]);
252+ // debug('MQTT Remove', this.discoveryTopicMap[topic]);
253253 switch ( this . discoveryTopicMap [ topic ] . type ) {
254254 case 'Service' :
255255 this . serviceCleanup ( this . discoveryTopicMap [ topic ] . uniq_id , existingAccessory ) ;
@@ -510,30 +510,34 @@ export class tasmotaPlatform implements DynamicPlatformPlugin {
510510
511511 autoCleanup ( accessory : PlatformAccessory ) : number | null {
512512 let timeoutID : number ;
513-
513+ // debug('autoCleanup', this.cleanup, accessory.displayName, accessory.context);
514514 // Check if 'stat_t' is available in the accessory context
515- if ( findVal ( accessory . context . device , 'stat_t' ) ) {
516- if ( accessory . context . timeout ) {
517- // Clear existing timeout if present
518- timeoutID = accessory . context . timeout ;
519- clearTimeout ( this . timeouts [ timeoutID ] ) ;
520- delete this . timeouts [ timeoutID ] ;
521- }
515+ if ( this . cleanup ) {
516+ if ( findVal ( accessory . context . device , 'stat_t' ) ) {
517+ if ( accessory . context . timeout ) {
518+ // Clear existing timeout if present
519+ timeoutID = accessory . context . timeout ;
520+ clearTimeout ( this . timeouts [ timeoutID ] ) ;
521+ delete this . timeouts [ timeoutID ] ;
522+ }
522523
523- // Create a new timeout ID and store it
524- timeoutID = this . timeoutCounter ++ ;
525- this . timeouts [ timeoutID ] = setTimeout (
526- this . accessoryCleanup . bind ( this ) ,
527- this . cleanup * 60 * 60 * 1000 , // Convert cleanup interval to milliseconds
528- accessory ,
529- ) ;
524+ // Create a new timeout ID and store it
525+ timeoutID = this . timeoutCounter ++ ;
526+ this . timeouts [ timeoutID ] = setTimeout (
527+ this . accessoryCleanup . bind ( this ) ,
528+ this . cleanup * 60 * 60 * 1000 , // Convert cleanup interval to milliseconds
529+ accessory ,
530+ ) ;
530531
531- // Save the new timeout ID in the accessory context for future clearing
532- accessory . context . timeout = timeoutID ;
532+ // Save the new timeout ID in the accessory context for future clearing
533+ accessory . context . timeout = timeoutID ;
533534
534- return timeoutID ;
535+ return timeoutID ;
536+ } else {
537+ // Return null if 'stat_t' is unavailable
538+ return null ;
539+ }
535540 } else {
536- // Return null if 'stat_t' is unavailable
537541 return null ;
538542 }
539543 }
0 commit comments