* Fix reconnect failure in some disconnect cases
* Remove duplicate republish function
This commit is contained in:
tsightler
2021-01-12 20:19:42 -05:00
parent a5b344faeb
commit 02d5124b62
3 changed files with 26 additions and 33 deletions

View File

@@ -597,24 +597,17 @@ class TuyaDevice {
// Retry connection every 10 seconds if unable to connect
async reconnect() {
if (!this.device.isConnected() && !this.reconnecting) {
if (!this.reconnecting) {
this.reconnecting = true
debugError('Error connecting to device id '+this.options.id+'...retry in 10 seconds.')
await utils.sleep(10)
if (this.connected) { return }
this.connectDevice()
if (!this.device.isConnected) {
this.connectDevice()
}
this.reconnecting = false
}
}
// Republish device discovery/state data (used for Home Assistant state topic)
async republish() {
const status = (this.device.isConnected()) ? 'online' : 'offline'
this.publishMqtt(this.baseTopic+'status', status)
await utils.sleep(1)
this.init()
}
// Republish device discovery/state data (used for Home Assistant state topic)
async republish() {
const status = (this.device.isConnected()) ? 'online' : 'offline'
@@ -648,4 +641,4 @@ class TuyaDevice {
}
}
module.exports = TuyaDevice
module.exports = TuyaDevice