Skip to content

Commit

Permalink
fix: could disconnect disconnected devices
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Mar 10, 2022
1 parent b8f62fa commit dba65f9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ class Device {
throw error;
}

_onDisconnected() {
this.connected = false;
this.lostConnection = false;
this.changed();
}

/** @private */
async _onConnectedHandler() {
this.log.info("connected.");
Expand All @@ -193,11 +199,10 @@ class Device {
}

async disconnect() {
const connectPromise = this.adapter.disconnect();
await waitFor(connectPromise, 2000, "Timed out while disconnecting.");
this.connected = false;
this.lostConnection = false;
this.changed();
if (this.connected) {
await waitFor(this.adapter.disconnect(), 2000, "Timed out while disconnecting.");
this._onDisconnected();
}
}

onChanged() {
Expand Down

0 comments on commit dba65f9

Please sign in to comment.