From 633d098206f2967638ecba6f358008d16b358e84 Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Mon, 6 Apr 2026 20:40:56 +0200 Subject: [PATCH] fix: store last_payload during MQTT topic discovery The discovery message handler was missing the payload parameter, so topics were saved without their last value. Co-Authored-By: Claude Opus 4.6 (1M context) --- display/middleware/src/modules/mqtt/topic-discovery.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/display/middleware/src/modules/mqtt/topic-discovery.ts b/display/middleware/src/modules/mqtt/topic-discovery.ts index 7603374..b9c1d88 100644 --- a/display/middleware/src/modules/mqtt/topic-discovery.ts +++ b/display/middleware/src/modules/mqtt/topic-discovery.ts @@ -93,11 +93,18 @@ export function startDiscovery(brokerId: number, prefix?: string): Promise { + const onMessage = (topic: string, payload: Buffer): void => { + const payloadStr = payload.toString(); if (!discoveredTopics.has(topic)) { discoveredTopics.add(topic); ensureTopicExists(brokerId, topic); } + // Always update last_payload so the user sees the latest value + const db = getDb(); + db.run( + 'UPDATE mqtt_topics SET last_payload = ? WHERE broker_id = ? AND topic = ?', + [payloadStr, brokerId, topic] + ); }; if (existingClient && existingClient.connected) {