Skip to content

Commit

Permalink
MQTT meter should not cache data with timestamp
Browse files Browse the repository at this point in the history
Fixes #58
  • Loading branch information
longzheng committed Dec 8, 2024
1 parent 2ca0c83 commit d3f1dd3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/meters/mqtt/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -37,7 +37,7 @@ export class MqttSiteSamplePoller extends SiteSamplePollerBase {
return;
}

this.cachedMessage = { date: new Date(), ...result.data };
this.cachedMessage = result.data;
});

void this.startPolling();
Expand All @@ -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() {
Expand Down

0 comments on commit d3f1dd3

Please sign in to comment.