Skip to content

Commit 68630ad

Browse files
authored
Merge pull request #365 from foxthefox/1.4.8
1.4.8 avg msg counter
2 parents d5a7340 + 536fe64 commit 68630ad

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/adapter_utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ async function createInfoStates(adapter, haenable) {
198198
native: {},
199199
});
200200
await adapter.setStateAsync('info.cntDevOnline', { val: 0, ack: true });
201+
await adapter.setObjectNotExistsAsync('info.efConnAvgLoad', {
202+
type: 'state',
203+
common: {
204+
name: '10s avg MSG count from EF-cloud',
205+
type: 'number',
206+
read: true,
207+
write: false,
208+
role: 'indicator',
209+
desc: '10s avg MSG count from EF-cloud',
210+
},
211+
native: {},
212+
});
213+
await adapter.setStateAsync('info.efConnAvgLoad', { val: 0, ack: true });
201214
if (haenable) {
202215
await adapter.setObjectNotExistsAsync('info.haConnection', {
203216
type: 'state',

main.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const mqtt = require('mqtt');
1818
let recon_timer = null;
1919
let lastQuotInterval = null;
2020
let haLoadInterval = null;
21+
let msgCalcInterval = null;
2122

2223
const version = require('./io-package.json').common.version;
2324

@@ -53,6 +54,8 @@ class EcoflowMqtt extends utils.Adapter {
5354
this.haDevices = null;
5455
this.haCounter = 0;
5556
this.haCountMem = 0;
57+
this.efCounter = 0;
58+
this.efCountMem = 0;
5659
this.onlineDevices = [];
5760

5861
this.on('ready', this.onReady.bind(this));
@@ -669,17 +672,20 @@ class EcoflowMqtt extends utils.Adapter {
669672
this.log.debug('EF no topics for subscription');
670673
}
671674
this.setState('info.connection', true, true);
675+
//avg load of receiving telegrams from EF cloud
676+
msgCalcInterval = this.setInterval(() => {
677+
const msgcnt = this.efCounter - this.efCountMem;
678+
this.efCountMem = this.efCounter;
679+
this.setState('info.efConnAvgLoad', { val: msgcnt, ack: true });
680+
}, 10 * 1000);
672681
});
673682

674683
this.client.on('message', async (topic, message) => {
675-
// message is Buffer
676-
// this.log.debug(topic + ' got ' + message.toString());
677-
678684
const msgtop = ef.getIdFromTopic(topic, this.mqttUserId);
679685
const msgtype = msgtop.msg;
680686
//this topic only contains the id of device
681687
topic = msgtop.topic;
682-
688+
this.efCounter++;
683689
let devtype = '';
684690
let logged = false;
685691
let devicelogged = false;
@@ -1301,11 +1307,15 @@ class EcoflowMqtt extends utils.Adapter {
13011307
}
13021308
if (lastQuotInterval) {
13031309
this.clearInterval(lastQuotInterval);
1304-
this.log.debug('lastQuotInterval interval stopped');
1310+
this.log.debug('lastQuotInterval interval stopped');
13051311
}
13061312
if (haLoadInterval) {
13071313
clearInterval(haLoadInterval);
1308-
this.log.debug('haConnAvgLoad interval stopped');
1314+
this.log.debug('haConnAvgLoad interval stopped');
1315+
}
1316+
if (msgCalcInterval) {
1317+
clearInterval(msgCalcInterval);
1318+
this.log.debug('msgCalc interval stopped');
13091319
}
13101320
if (this.haClient && this.haDevices) {
13111321
// await ha.publishAsync(this, this.config.haTopic + '/iob/info/status', 'offline', 1);

0 commit comments

Comments
 (0)