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.
When Home Assistant becomes unreachable (WiFi dropout, HA restart, etc.),
the module now:
- Detects connectivity errors (ENETUNREACH, timeout, etc.)
- Opens a circuit breaker that stops ALL template evaluations immediately
- Runs a single coalesced health check with exponential backoff (15s→300s)
- Queues pending evaluations and replays them when HA comes back
- Suppresses error log spam while circuit is open
Previously, each of the 11 sections would independently fail + retry,
flooding the event loop with 30+ error callbacks in the same millisecond
and freezing Electron's renderer.
Fixes repeated MagicMirror freezes during transient network outages.
The conditional config.debuglogging checks were not working reliably
in node_helper context. Removed debug logging from onStateChangedEvent
entirely (it fires on every entity state change - multiple times per
second for power sensors). WS disconnect promoted to info level since
it's actually useful.
- Add 10 second timeout to template evaluation HTTP calls
- Add retry logic that schedules retry after 30 seconds on failure
- Maintains existing error handling while preventing silent failures
- Fixes issue where template errors cause data to stay stale until next WebSocket event