Fix stale data after HA outage recovery
Some checks failed
Release Drafter / update_release_draft (push) Failing after 5s

Two bugs caused the module to show outdated data permanently after HA
came back online:

1. refreshTimer was only checked at section level, but config sets it at
   the module config level. The setInterval never started, so there was
   no periodic re-render fallback when the WebSocket died.

2. _closeCircuit replayed queued templates but never reconnected the
   WebSocket. Without WS, no state_changed events fire, so the only
   render path was the (broken) refreshTimer.

Also fixes a race condition in _healthCheck where breaker.state was
briefly set to 'closed' before calling _openCircuit on failure. Now
uses 'half-open' state instead.
This commit is contained in:
Clawd
2026-03-01 08:59:15 +00:00
parent de03a33138
commit 5cdc4e2ce2
2 changed files with 35 additions and 9 deletions

View File

@@ -52,15 +52,29 @@ Module.register("MMM-HomeAssistantDisplay", {
entity: section.triggerEntities[entity]
});
}
// Set up a timer to trigger re-rendering outside of any entity state update
if (section.refreshTimer) {
setInterval(()=> {
this.renderTemplates("timeout");
this.updateDom();
}, section.refreshTimer * 1000);
}
}
// Refresh timer: check section-level first, then fall back to config-level.
// One interval per module instance — renderTemplates already hits all sections.
var refreshInterval = null;
if (this.config.sections) {
for (const sectioid in this.config.sections) {
if (this.config.sections[sectioid].refreshTimer) {
refreshInterval = this.config.sections[sectioid].refreshTimer;
break;
}
}
}
if (!refreshInterval && this.config.refreshTimer) {
refreshInterval = this.config.refreshTimer;
}
if (refreshInterval) {
setInterval(() => {
this.renderTemplates("refreshTimer");
this.updateDom();
}, refreshInterval * 1000);
}
this.renderTemplates("foo");
self.updateDom(self.config.animationSpeed);
},