Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async disconnect() {
logger('disconnecting from Plejd');
if (this.isConnected) {
clearInterval(this.pingRef);
if (this.peripheral) {
try {
// disconnect
await this.peripheral.disconnect();
// we need to reset the ble adapter too
noble._bindings._hci.reset();
// wait 200 ms for reset command to take effect :)
sleep.msleep(200);
// now we're ready to connect again
}
catch (error) {
console.log('error: unable to disconnect from Plejd: ' + error);
return Promise.resolve(false);
}
this.isConnected = false;
logger('disconnected from Plejd');
return Promise.resolve(true);
}