Skip to content

Commit 8be9de4

Browse files
Tiwasclaude
andcommitted
fix(flow-doctor): trace tab now shows events on screen
- Inject a synthetic "Tracing started" event so the log is visibly wired up even before any real Homey event fires - Remove the seeding-skip in pollFlowExecutions: startTrace() already baselines all known lastExecuted timestamps, so any unseen flow ID hitting the poller is a genuine first-time run - Defensively call manager.connect() on devices/flow/logic/apps since some homey-api builds need it before realtime fires - Add console.log diagnostics on subscribe/dispatch so users can see in DevTools which events are arriving Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f7e8006 commit 8be9de4

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

docs/tools/flow-doctor.html

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,28 @@ <h2 class="text-xl font-bold text-gray-900" data-i18n="bug.title">Report a bug</
15871587
this.traceDevicesById.clear();
15881588
Object.values(devices).forEach(d => this.traceDevicesById.set(d.id, d));
15891589

1590+
// Synthetic startup marker so the user can see the log is wired up even if no real
1591+
// events fire yet.
1592+
this.addTraceEvent({
1593+
cat: 'app',
1594+
title: '✅ Tracing started',
1595+
subject: '',
1596+
detail: `${this.traceFlowsById.size} flows · ${this.traceDevicesById.size} devices baselined`,
1597+
raw: { flows: this.traceFlowsById.size, devices: this.traceDevicesById.size },
1598+
});
1599+
1600+
// The cloud-bridged HomeyAPI sometimes needs an explicit connect() on each manager
1601+
// before realtime events flow. It's a no-op on managers that auto-connect.
1602+
for (const mgrName of ['devices', 'flow', 'logic', 'apps']) {
1603+
try {
1604+
const mgr = this.api[mgrName];
1605+
if (mgr && typeof mgr.connect === 'function') {
1606+
await mgr.connect();
1607+
console.log(`[trace] connected manager: ${mgrName}`);
1608+
}
1609+
} catch (e) { console.warn(`[trace] connect(${mgrName}) failed:`, e); }
1610+
}
1611+
15901612
// Subscribe to WebSocket events. The HomeyAPI v3 managers extend EventEmitter and emit
15911613
// events like "device.update", "flow.update", "variable.update", "app.update".
15921614
// We wrap each subscription in try/catch — if a particular manager isn't exposed in this
@@ -1684,13 +1706,15 @@ <h2 class="text-xl font-bold text-gray-900" data-i18n="bug.title">Report a bug</
16841706
attachManagerListener(managerName, eventName, handler) {
16851707
try {
16861708
const mgr = this.api && this.api[managerName];
1687-
if (!mgr || typeof mgr.on !== 'function') return;
1709+
if (!mgr || typeof mgr.on !== 'function') { console.warn(`[trace] no listener support on ${managerName}`); return; }
16881710
const wrapped = (payload) => {
1689-
try { handler(payload); } catch (e) { /* swallow per-event errors */ }
1711+
console.log(`[trace] ${managerName}.${eventName}`, payload);
1712+
try { handler(payload); } catch (e) { console.warn('[trace] handler error', e); }
16901713
};
16911714
mgr.on(eventName, wrapped);
16921715
this.traceListeners.push({ mgr, eventName, wrapped });
1693-
} catch (e) { /* manager not available — ignore */ }
1716+
console.log(`[trace] subscribed: ${managerName}.${eventName}`);
1717+
} catch (e) { console.warn(`[trace] subscribe failed: ${managerName}.${eventName}`, e); }
16941718
}
16951719

16961720
diffCapabilities(prev, next) {
@@ -1721,9 +1745,10 @@ <h2 class="text-xl font-bold text-gray-900" data-i18n="bug.title">Report a bug</
17211745
if (!flow.lastExecuted) continue;
17221746
const prev = this.traceLastExec.get(flow.id);
17231747
if (prev === flow.lastExecuted) continue;
1724-
const seeding = prev === undefined;
1748+
// startTrace() already seeded every flow that had a prior lastExecuted, so a
1749+
// prev===undefined here means this flow ran for the very first time during
1750+
// this tracing session — that's a real event worth reporting.
17251751
this.traceLastExec.set(flow.id, flow.lastExecuted);
1726-
if (seeding) continue;
17271752
this.addTraceEvent({
17281753
cat: 'flow',
17291754
title: this.t('trace.flowRan') + (flow._type === 'advanced' ? ' (advanced)' : ''),

0 commit comments

Comments
 (0)