Skip to content

Commit

Permalink
Clear timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
XHunter74 committed Apr 24, 2024
1 parent ef42a35 commit 244c436
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const utils = require('@iobroker/adapter-core');

const MinPollInterval = 1000;
const MaxPollInterval = 60000;
const CheckDeviceTimeout = 1000;
const CheckDeviceTimeoutMs = 1000;
let CheckDeviceTimeout = null;

class GreeHvac extends utils.Adapter {

Expand Down Expand Up @@ -96,15 +97,16 @@ class GreeHvac extends utils.Adapter {
}

checkDevices() {
this.setTimeout(async () => {
CheckDeviceTimeout = this.setTimeout(async () => {
const inactiveDevices = this.activeDevices.filter(device => device.isActive === false);
if (inactiveDevices.length > 0) {
await this.setStateAsync('info.connection', { val: false, ack: true });
} else {
await this.setStateAsync('info.connection', { val: true, ack: true });
}
this.clearTimeout(CheckDeviceTimeout);
this.checkDevices();
}, CheckDeviceTimeout);
}, CheckDeviceTimeoutMs);
}

/**
Expand Down Expand Up @@ -256,6 +258,9 @@ class GreeHvac extends utils.Adapter {
for (const deviceId in this.intervals) {
this.clearInterval(this.intervals[deviceId]);
}
if (CheckDeviceTimeout) {
this.clearTimeout(CheckDeviceTimeout);
}
callback();
} catch (error) {
this.log.error(`Error in onUnload: ${error}`);
Expand Down

0 comments on commit 244c436

Please sign in to comment.