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) <noreply@anthropic.com>
This commit is contained in:
Christian Mueller 2026-04-06 20:40:56 +02:00
parent 73179f3040
commit 633d098206

View File

@ -93,11 +93,18 @@ export function startDiscovery(brokerId: number, prefix?: string): Promise<MqttT
resolve(getTopicsForBroker(brokerId)); resolve(getTopicsForBroker(brokerId));
}; };
const onMessage = (topic: string): void => { const onMessage = (topic: string, payload: Buffer): void => {
const payloadStr = payload.toString();
if (!discoveredTopics.has(topic)) { if (!discoveredTopics.has(topic)) {
discoveredTopics.add(topic); discoveredTopics.add(topic);
ensureTopicExists(brokerId, 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) { if (existingClient && existingClient.connected) {