Skip to content

Commit

Permalink
Fix bug that lead to devices not reconnecting (#40)
Browse files Browse the repository at this point in the history
* Update tuya-device.js

* Update tuya-device.js
  • Loading branch information
bewee authored Feb 4, 2022
1 parent 6964b18 commit c70b890
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/devices/tuya-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class TuyaDevice extends Device {
this.tuyapi.connect().catch((err) => {
if (oldconnected) {
console.error(this.id, 'Error during tuyapi connect', err);
this.run();
}
});
}).bind(this), this.adapter.config.timeout*1000);
Expand Down Expand Up @@ -117,12 +118,16 @@ class TuyaDevice extends Device {
console.debug(this.id, 'Already dead!');
return;
}
this.tuyapi.find({timeout: this.adapter.config.timeout}).then((() => {
this.tuyapi.find({timeout: this.adapter.config.timeout}).then(() => {
console.debug(this.id, 'Device found. Connecting...');
this.tuyapi.connect();
}).bind(this)).catch((() => {
this.run();
}).bind(this));
this.tuyapi.connect().catch((err) => {
console.debug(this.id, 'Connect failed', err);
setTimeout(this.run.bind(this), this.adapter.config.timeout * 1000);
});
}).catch((err) => {
console.debug(this.id, 'Find failed', err);
setTimeout(this.run.bind(this), this.adapter.config.timeout * 1000);
});
}

stop() {
Expand Down

0 comments on commit c70b890

Please sign in to comment.