Skip to content

Commit

Permalink
fix: throttle firmware update progress events for OTA
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Oct 19, 2023
1 parent cfa8822 commit 229e420
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/zwave-js/src/lib/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ import {
getErrorMessage,
pick,
stringify,
throttle,
} from "@zwave-js/shared";
import { distinct } from "alcalzone-shared/arrays";
import { wait } from "alcalzone-shared/async";
Expand Down Expand Up @@ -4844,6 +4845,13 @@ protocol version: ${this.protocolVersion}`;
return result;
}

// Throttle the progress emitter so applications can handle the load of events
const notifyProgress = throttle(
(progress) => this.emit("firmware update progress", this, progress),
250,
true,
);

// Perform all firmware updates in sequence
let updateResult!: Awaited<
ReturnType<ZWaveNode["doFirmwareUpdateInternal"]>
Expand Down Expand Up @@ -4890,7 +4898,7 @@ protocol version: ${this.protocolVersion}`;
2,
),
};
this.emit("firmware update progress", this, progress);
notifyProgress(progress);

// When this file is done, add the fragments to the total, so we can compute the total progress correctly
if (fragment === total) {
Expand Down

0 comments on commit 229e420

Please sign in to comment.