From d3f1dd37141f0c994882a91d649975029f2daff9 Mon Sep 17 00:00:00 2001 From: Long Zheng Date: Sun, 8 Dec 2024 21:00:00 +1100 Subject: [PATCH] MQTT meter should not cache data with timestamp Fixes #58 --- src/meters/mqtt/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/meters/mqtt/index.ts b/src/meters/mqtt/index.ts index 5058877..055eb13 100644 --- a/src/meters/mqtt/index.ts +++ b/src/meters/mqtt/index.ts @@ -1,12 +1,12 @@ import mqtt from 'mqtt'; import { type Config } from '../../helpers/config.js'; import { SiteSamplePollerBase } from '../siteSamplePollerBase.js'; -import { type SiteSample } from '../siteSample.js'; +import { type SiteSampleData, type SiteSample } from '../siteSample.js'; import { siteSampleDataSchema } from '../siteSample.js'; export class MqttSiteSamplePoller extends SiteSamplePollerBase { private client: mqtt.MqttClient; - private cachedMessage: SiteSample | null = null; + private cachedMessage: SiteSampleData | null = null; constructor({ mqttConfig, @@ -37,7 +37,7 @@ export class MqttSiteSamplePoller extends SiteSamplePollerBase { return; } - this.cachedMessage = { date: new Date(), ...result.data }; + this.cachedMessage = result.data; }); void this.startPolling(); @@ -49,7 +49,7 @@ export class MqttSiteSamplePoller extends SiteSamplePollerBase { throw new Error('No site sample data on MQTT'); } - return this.cachedMessage; + return { date: new Date(), ...this.cachedMessage }; } override onDestroy() {