Skip to content

Commit 892ee2b

Browse files
Fix for disabling cleanup not working (#54)
1 parent a0da217 commit 892ee2b

File tree

5 files changed

+39
-29
lines changed

5 files changed

+39
-29
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/).
44

5+
## 0.2.2 (2024-12-23)
6+
7+
## [Version 0.2.2](https://github.com/northernman54/homebridge-tasmota/compare/0.2.1...0.2.2)
8+
9+
#### Changes
10+
11+
- Fix for cleanup = 0 ( no cleanup )
12+
513
## 0.2.1 (2024-12-14)
614

7-
## [Version 0.1.12](https://github.com/northernman54/homebridge-tasmota/compare/0.2.0...0.2.1)
15+
## [Version 0.2.1](https://github.com/northernman54/homebridge-tasmota/compare/0.2.0...0.2.1)
816

917
#### Changes
1018

@@ -13,7 +21,7 @@ All notable changes to this project will be documented in this file. This projec
1321

1422
## 0.2.0 (2024-12-10)
1523

16-
## [Version 0.1.12](https://github.com/northernman54/homebridge-tasmota/compare/v0.1.18...v0.2.0)
24+
## [Version 0.2.0](https://github.com/northernman54/homebridge-tasmota/compare/v0.1.18...v0.2.0)
1725

1826
#### Changes
1927

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"displayName": "Tasmota",
33
"name": "homebridge-tasmota",
4-
"version": "0.2.1",
4+
"version": "0.2.2",
55
"type": "module",
66
"description": "Homebridge plugin for Tasmota devices leveraging home assistant auto discovery.",
77
"license": "Apache-2.0",

src/tasmotaPlatform.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

test/hbConfig/config.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@
2525
"platform": "Tasmota",
2626
"name": "Tasmota",
2727
"mqttHost": "mqtt.local",
28-
"cleanup": 0.1,
2928
"history": false,
3029
"debug": true,
30+
"cleanup": 0,
3131
"filterAllow": [
32-
"AC5811",
33-
"CBA0E5",
34-
"302F1B"
32+
"130C86"
3533
],
3634
"filterDeny": [
3735
"5673B2",

0 commit comments

Comments
 (0)