Cache ESPHome profile metadata and stop polling hidden tabs (0.2.19)

/api/inventory re-read every ESPHome profile with pure-Python PyYAML up to
four times per request, which blocked the event loop for seconds on a Pi.
Profiles are now cached per file on (inode, mtime_ns, size), parsed with
libyaml when available, and read once per request. The sync loop computes
the inventory once per iteration. The page pauses polling while hidden.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Max Gramser
2026-09-13 11:19:16 +02:00
parent ef0ca8b350
commit b67cd33fb3
7 changed files with 117 additions and 41 deletions
+13 -4
View File
@@ -1014,12 +1014,21 @@ window.addEventListener("beforeunload", (e) => {
}
});
refresh();
(function poll() {
setTimeout(async () => {
await refresh();
// Poll only while the tab is visible; a hidden tab would otherwise keep the add-on busy.
let pollTimer;
function poll() {
clearTimeout(pollTimer);
pollTimer = setTimeout(async () => {
if (!document.hidden) await refresh();
poll();
}, inventory.updates?.busy ? 3000 : 10000);
})();
}
poll();
document.addEventListener("visibilitychange", async () => {
if (document.hidden) return;
await refresh();
poll();
});
// Shared firmware workspace; always select a concrete profile and upload target.
let firmwarePoll;