Skip to content

Commit

Permalink
Set alive states to false if the adapter unloaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
XHunter74 committed May 8, 2024
1 parent 3a0cc44 commit e7ad7ff
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,10 @@ class ApcUpsAdapter extends utils.Adapter {
try {
this.clearTimeout(this.timeoutId);
this.clearTimeout(this.availabilityTimeout);

await this.setAliveStatesToFalse();
if (this.apcAccess != null && this.apcAccess.isConnected === true) {
await this.apcAccess.disconnect();
this.apcAccess = null;
this.log.info('ApcAccess client is disconnected');
}
callback();
Expand All @@ -401,6 +402,21 @@ class ApcUpsAdapter extends utils.Adapter {
callback();
}
}

async setAliveStatesToFalse() {
try {
if (this.ipAddressStates.length > 0) {
for (const ipAddress of this.ipAddressStates) {
const upsId = ipAddress.split('.')[2];
const aliveStateName = `${upsId}.info.alive`;
this.setState(aliveStateName, false, true);
}
}
this.setState('info.connection', false, true);
} catch (error) {
this.log.error(`Error in setAliveStatesToFalse: ${error}`);
}
}
}

if (require.main !== module) {
Expand Down

0 comments on commit e7ad7ff

Please sign in to comment.