mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-21 18:19:51 +00:00
Prevent devices always being pinged at exactly the same time (#6133)
* Add availability lag of rand 10% from timeout * Update availability.js * Update utils.js Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
This commit is contained in:
co-authored by
Koen Kanters
parent
1b76cd0ae5
commit
1df52cc6e8
+2
-1
@@ -3,6 +3,7 @@
|
||||
.git
|
||||
.github
|
||||
.gitignore
|
||||
.idea
|
||||
.npmrc
|
||||
.travis*
|
||||
.travis.yml
|
||||
@@ -12,4 +13,4 @@ images
|
||||
node_modules
|
||||
scripts
|
||||
test
|
||||
update.sh
|
||||
update.sh
|
||||
|
||||
@@ -14,6 +14,13 @@ const pingableEndDevices = [
|
||||
];
|
||||
|
||||
const Hours25 = 1000 * 60 * 60 * 25;
|
||||
const AvailabilityLagRatio = 0.1;
|
||||
|
||||
|
||||
function timeoutLag(timeout, ratio) {
|
||||
const lag = timeout * ratio;
|
||||
return Math.floor(Math.random() * Math.floor(lag));
|
||||
}
|
||||
|
||||
/**
|
||||
* This extensions pings devices to check if they are online.
|
||||
@@ -137,10 +144,11 @@ class Availability extends Extension {
|
||||
}
|
||||
|
||||
setTimerPingable(device) {
|
||||
const timeout = this.availability_timeout + timeoutLag(this.availability_timeout, AvailabilityLagRatio);
|
||||
clearTimeout(this.timers[device.ieeeAddr]);
|
||||
this.timers[device.ieeeAddr] = setTimeout(async () => {
|
||||
await this.handleIntervalPingable(device);
|
||||
}, utils.secondsToMilliseconds(this.availability_timeout));
|
||||
}, utils.secondsToMilliseconds(timeout));
|
||||
}
|
||||
|
||||
async stop() {
|
||||
|
||||
Reference in New Issue
Block a user