Skip to content

Commit

Permalink
switch to intervall
Browse files Browse the repository at this point in the history
  • Loading branch information
arteck authored Oct 26, 2023
1 parent c182c43 commit 7f62e17
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { default: AxiosDigestAuth } = require('@mhoc/axios-digest-auth');

let _batteryNum = 0;
let _arrayNum = 0;
let requestTimeout = null;
let _requestInterval = null;
let interval = 0;

let PASSWORD = "";
Expand Down Expand Up @@ -58,7 +58,7 @@ class bydbattControll extends utils.Adapter {
*/
onUnload(callback) {
try {
if (requestTimeout) clearTimeout(requestTimeout);
if (_requestInterval) clearInterval(_requestInterval);

this.log.info('cleaned everything up...');
this.setState('info.connection', false, true);
Expand All @@ -72,9 +72,6 @@ class bydbattControll extends utils.Adapter {
async getInfos() {
this.log.debug(`get Information`);
try {

if (requestTimeout) clearTimeout(requestTimeout);

for (var a = 1; a < _arrayNum+1; a++) {
let htmlHome = await this.getDatenHome(this.config.ip);
const resHome = await this.updateDeviceHome(htmlHome.data);
Expand All @@ -88,9 +85,11 @@ class bydbattControll extends utils.Adapter {
}
}

requestTimeout = setTimeout(async () => {
this.getInfos();
}, interval);
if (!_requestInterval) {
_requestInterval = setInterval(async () => {
this.getInfos();
}, interval);
}
} catch (err) {
this.log.error(`no Device available error: ${err}`);
}
Expand Down

0 comments on commit 7f62e17

Please sign in to comment.