* 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

36
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "tuya-mqtt",
"version": "3.0.2",
"version": "3.0.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -18,13 +18,13 @@
}
},
"@tuyapi/cli": {
"version": "1.13.6",
"resolved": "https://registry.npmjs.org/@tuyapi/cli/-/cli-1.13.6.tgz",
"integrity": "sha512-xvQfhFkhc0issQClzHSCrRuFyq6exBloKW0ZCIfWqRaZ9bPuDLjNv3UDFD7ywFSsBWiWNX28kGSAIM5QX2glNQ==",
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/@tuyapi/cli/-/cli-1.15.0.tgz",
"integrity": "sha512-V85STIKtkDM+t8G08PUdL4klnnGmJU1qcPQF6pYRUn//iSlm1AD0CkNZ9Qll+nK2rpPB/2X5wJCwe8dCp1MEnQ==",
"requires": {
"@tuyapi/link": "^0.3.3",
"@tuyapi/openapi": "^1.2.0",
"@tuyapi/stub": "^0.1.4",
"@tuyapi/stub": "^0.2.0",
"cli-table3": "^0.6.0",
"colors": "^1.4.0",
"commander": "^5.1.0",
@@ -72,9 +72,9 @@
}
},
"@tuyapi/stub": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/@tuyapi/stub/-/stub-0.1.4.tgz",
"integrity": "sha512-uF2u1Z78Qif3hK92RYxMG4AbjedNRZYmM1jIvegf4KUfDVV/BhHFooz2y3Q28jPl5Q+H39QY/WBH2bMiXMAg/g==",
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/@tuyapi/stub/-/stub-0.2.0.tgz",
"integrity": "sha512-QVwHf1KexAJw8mgmkyxXH4t5sToK0Ai3O8PFKNqgbgx6LOWciqOOcV99xw+6UwGa2iyvW/PnFoMqVRuYy1EgQQ==",
"requires": {
"debug": "^4.1.1",
"tuyapi": "^5.0.0"
@@ -346,12 +346,12 @@
}
},
"call-bind": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.0.tgz",
"integrity": "sha512-AEXsYIyyDY3MCzbwdhzG3Jx1R0J2wetQyUynn6dYHAO+bg8l1k7jwZtRv4ryryFs7EP+NDlikJlVe59jr0cM2w==",
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
"requires": {
"function-bind": "^1.1.1",
"get-intrinsic": "^1.0.0"
"get-intrinsic": "^1.0.2"
}
},
"callback-stream": {
@@ -1094,9 +1094,9 @@
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"ini": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz",
"integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew=="
"version": "1.3.7",
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.7.tgz",
"integrity": "sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ=="
},
"inquirer": {
"version": "7.3.3",
@@ -2302,9 +2302,9 @@
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"tuyapi": {
"version": "6.1.2",
"resolved": "https://registry.npmjs.org/tuyapi/-/tuyapi-6.1.2.tgz",
"integrity": "sha512-C8ewskhjWJHjUlgCRItEilkrZ3z2uH4rkSJMRTG73EQgMutr/9R3EfoyxAMUQIQxvsmODjMsXpKX07+tqIQ7tg==",
"version": "6.1.3",
"resolved": "https://registry.npmjs.org/tuyapi/-/tuyapi-6.1.3.tgz",
"integrity": "sha512-/7nI3Dr3NwWMDnrz7MSRQw9lW3R5i6lnRStIjPgybZ1Wj1jL/PHuRfeNBPAb8ocNbLQN6JqxbefY4awXmp+LqQ==",
"requires": {
"debug": "4.1.1",
"p-queue": "6.6.1",

View File

@@ -1,6 +1,6 @@
{
"name": "tuya-mqtt",
"version": "3.0.2",
"version": "3.0.3",
"description": "Control Tuya devices locally via MQTT",
"homepage": "https://github.com/TheAgentK/tuya-mqtt#readme",
"main": "tuya-mqtt.js",
@@ -13,13 +13,13 @@
},
"license": "ISC",
"dependencies": {
"@tuyapi/cli": "^1.13.6",
"@tuyapi/cli": "^1.15.0",
"color-convert": "^2.0.1",
"debug": "^4.3.1",
"json5": "^2.1.3",
"mqtt": "^4.2.6",
"supports-color": "^8.1.0",
"tuyapi": "^6.1.2",
"tuyapi": "^6.1.3",
"mathjs": "8.1.1"
},
"repository": {