Skip to content

Commit 8b8a3e5

Browse files
committed
fix: unref timers
1 parent cffd604 commit 8b8a3e5

25 files changed

Lines changed: 95 additions & 61 deletions

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.4.11/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.5.0/schema.json",
33
"vcs": {
44
"enabled": true,
55
"clientKind": "git",

src/converters/fromZigbee.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ export const occupancy_with_timeout: Fz.Converter<"msOccupancySensing", undefine
597597
const timer = setTimeout(() => {
598598
publish({occupancy: false});
599599
}, timeout * 1000);
600+
timer.unref();
600601

601602
globalStore.putValue(msg.endpoint, "occupancy_timer", timer);
602603
}
@@ -1100,6 +1101,7 @@ export const ias_vibration_alarm_1_with_timeout: Fz.Converter<"ssIasZone", undef
11001101
const timer = setTimeout(() => {
11011102
publish({vibration: false});
11021103
}, timeout * 1000);
1104+
timer.unref();
11031105

11041106
globalStore.getValue(msg.endpoint, "timers").push(timer);
11051107
}
@@ -1294,6 +1296,7 @@ export const ias_occupancy_alarm_1_with_timeout: Fz.Converter<"ssIasZone", undef
12941296

12951297
if (timeout !== 0) {
12961298
const timer = setTimeout(() => publish({occupancy: false}), timeout * 1000);
1299+
timer.unref();
12971300
globalStore.putValue(msg.endpoint, "timer", timer);
12981301
}
12991302

@@ -1471,6 +1474,7 @@ export const command_move: Fz.Converter<"genLevelCtrl", undefined, ["commandMove
14711474
const deltaProperty = postfixWithEndpointName("action_brightness_delta", msg, model, meta);
14721475
publish({[property]: brightness, [deltaProperty]: delta});
14731476
}, intervalOpts);
1477+
timer.unref();
14741478

14751479
globalStore.putValue(msg.endpoint, "simulated_brightness_timer", timer);
14761480
}
@@ -1912,6 +1916,7 @@ export const checkin_presence: Fz.Converter<"genPollCtrl", undefined, ["commandC
19121916
clearTimeout(globalStore.getValue(msg.endpoint, "timer"));
19131917

19141918
const timer = setTimeout(() => publish({presence: false}), timeout * 1000);
1919+
timer.unref();
19151920
globalStore.putValue(msg.endpoint, "timer", timer);
19161921

19171922
return {presence: true};

src/devices/candeo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ const fzLocal = {
135135
}
136136
globalStore.putValue(endpoint, "button_click_count", 0);
137137
}, timeout);
138+
timer.unref();
138139
globalStore.putValue(endpoint, "timer", timer);
139140
},
140141
} satisfies Fz.Converter<"genOnOff", undefined, ["attributeReport", "readResponse"]>,

src/devices/echostar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const fzLocal = {
1919

2020
const lookup: KeyValueAny = {commandOn: "bell1", commandOff: "bell2"};
2121
const timer = setTimeout(() => globalStore.getValue(msg.endpoint, "action").pop(), timeout * 1000);
22+
timer.unref();
2223

2324
const list = globalStore.getValue(msg.endpoint, "action");
2425
if (list.length === 0 || list.length > 4) {

src/devices/fireangel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const fzLocal = {
1919

2020
if (testActive) {
2121
const timeout = setTimeout(() => publish({test: false}), 8000);
22+
timeout.unref();
2223
globalStore.putValue(msg.endpoint, "lastTestTimeout", timeout);
2324
}
2425

src/devices/javis.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const fzLocal = {
3636

3737
clearTimeout(globalStore.getValue(msg.endpoint, "timer"));
3838
const timer = setTimeout(() => publish({action: "lock", state: "LOCK"}), 2 * 1000);
39+
timer.unref();
3940
globalStore.putValue(msg.endpoint, "timer", timer);
4041

4142
return {

src/devices/kmpcil.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function handleKmpcilPresence(
4646
// Stop existing timer because motion is detected and set a new one.
4747
clearTimeout(globalStore.getValue(msg.endpoint, "timer"));
4848
const timer = setTimeout(() => publish({presence: false}), timeout * 1000);
49+
timer.unref();
4950
globalStore.putValue(msg.endpoint, "timer", timer);
5051

5152
return {presence: true};

src/devices/lidl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const valueConverterLocal = {
110110
ts.iteration_start_timestamp = Date.now();
111111
if (ts.timer > 1) {
112112
// report every minute
113-
ts.iteration_inverval = setInterval(() => {
113+
const interval = setInterval(() => {
114114
const now = Date.now();
115115
const wateringEndTime = ts.iteration_start_timestamp + ts.timer * 60 * 1000;
116116
const timeLeftInMinutes = Math.round((wateringEndTime - now) / 1000 / 60);
@@ -123,6 +123,8 @@ const valueConverterLocal = {
123123
});
124124
}
125125
}, 60 * 1000);
126+
ts.iteration_inverval = interval;
127+
interval.unref();
126128
}
127129
// initial reporting
128130
result.time_left = ts.timer;

src/devices/mindy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ const tzLocal = {
6666
} catch {
6767
/* Do nothing */
6868
}
69-
setTimeout(() => retryRead(attempts - 1), 10000);
69+
const timer = setTimeout(() => retryRead(attempts - 1), 10000);
70+
timer.unref();
7071
}
7172
};
7273

src/devices/nous.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ export const definitions: DefinitionWithExtend[] = [
5151
from: (v: boolean, meta, options, publish) => {
5252
if (!v) return false;
5353

54-
setTimeout(() => {
54+
const timer = setTimeout(() => {
5555
publish({warming_up: false});
5656
}, 120 * 1000);
57+
timer.unref();
5758
return true;
5859
},
5960
},

0 commit comments

Comments
 (0)