mirror of
https://github.com/lehanspb/tuya-mqtt.git
synced 2025-12-18 00:10:20 +00:00
Update to 3.0.2 (#63)
* Update 3.0.2 * Fix (hopefully) uninitialized key values for devices which block get requests for some DPS values based on operating mode (seen with at least one RGBTW light that will not return color DPS key while in white mode). * Modify HSB/HSBHEX guessing in RGBTW light to attempt to deal with issue above * Implement automatic reconnect when device disconnects socket on it's side * Update package dependencies to latest versions
This commit is contained in:
@@ -148,7 +148,7 @@ class RGBTWLight extends TuyaDevice {
|
||||
const mode2 = await this.device.get({"dps": 2})
|
||||
const mode21 = await this.device.get({"dps": 21})
|
||||
if (mode2 && (mode2 === 'white' || mode2 === 'colour' || mode2.toString().includes('scene'))) {
|
||||
debug('Detected probably Tuya color bulb at DPS 1-5, checking more details...')
|
||||
debug('Detected likely Tuya color bulb at DPS 1-5, checking more details...')
|
||||
this.guess = {'dpsPower': 1, 'dpsMode': 2, 'dpsWhiteValue': 3, 'whiteValueScale': 255, 'dpsColorTemp': 4, 'colorTempScale': 255, 'dpsColor': 5}
|
||||
} else if (mode21 && (mode21 === 'white' || mode21 === 'colour' || mode21.toString().includes('scene'))) {
|
||||
debug('Detected likely Tuya color bulb at DPS 20-24, checking more details...')
|
||||
@@ -159,14 +159,18 @@ class RGBTWLight extends TuyaDevice {
|
||||
debug('Attempting to detect if bulb supports color temperature...')
|
||||
const colorTemp = await this.device.get({"dps": this.guess.dpsColorTemp})
|
||||
if (colorTemp !== '' && colorTemp >= 0 && colorTemp <= this.guess.colorTempScale) {
|
||||
debug('Detected likely color temerature support')
|
||||
debug('Detected likely color temperature support')
|
||||
} else {
|
||||
debug('No color temperature support detected')
|
||||
this.guess.dpsColorTemp = 0
|
||||
}
|
||||
debug('Attempting to detect Tuya color format used by device...')
|
||||
const color = await this.device.get({"dps": this.guess.dpsColor})
|
||||
if (this.guess.dpsPower === 1) {
|
||||
this.guess.colorType = (color && color.length === 12) ? 'hsb' : 'hsbhex'
|
||||
} else {
|
||||
this.guess.colorType = (color && color.length === 14) ? 'hsbhex' : 'hsb'
|
||||
}
|
||||
debug ('Detected Tuya color format '+this.guess.colorType.toUpperCase())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ class TuyaDevice {
|
||||
|
||||
// Missed heartbeat monitor
|
||||
this.heartbeatsMissed = 0
|
||||
this.reconnecting = false
|
||||
|
||||
// Build the MQTT topic for this device (friendly name or device id)
|
||||
if (this.options.name) {
|
||||
@@ -85,19 +86,19 @@ class TuyaDevice {
|
||||
})
|
||||
|
||||
// On disconnect perform device specific disconnect
|
||||
this.device.on('disconnected', () => {
|
||||
this.device.on('disconnected', async () => {
|
||||
this.connected = false
|
||||
this.publishMqtt(this.baseTopic+'status', 'offline')
|
||||
debug('Disconnected from device ' + this.toString())
|
||||
await utils.sleep(5)
|
||||
this.reconnect()
|
||||
})
|
||||
|
||||
// On connect error call reconnect
|
||||
this.device.on('error', async (err) => {
|
||||
debugError(err)
|
||||
await utils.sleep(1)
|
||||
if (!this.device.isConnected()) {
|
||||
this.reconnect()
|
||||
}
|
||||
})
|
||||
|
||||
// On heartbeat reset heartbeat timer
|
||||
@@ -112,9 +113,9 @@ class TuyaDevice {
|
||||
this.connected = false
|
||||
for (let topic in this.deviceTopics) {
|
||||
const key = this.deviceTopics[topic].key
|
||||
if (!this.dps[key]) { this.dps[key] = {} }
|
||||
try {
|
||||
const result = await this.device.get({"dps": key})
|
||||
this.dps[key].val = result
|
||||
this.dps[key].val = await this.device.get({"dps": key})
|
||||
this.dps[key].updated = true
|
||||
} catch {
|
||||
debugError('Could not get value for device DPS key '+key)
|
||||
@@ -596,10 +597,22 @@ class TuyaDevice {
|
||||
|
||||
// Retry connection every 10 seconds if unable to connect
|
||||
async reconnect() {
|
||||
if (!this.device.isConnected() && !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()
|
||||
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)
|
||||
|
||||
690
package-lock.json
generated
690
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tuya-mqtt",
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.2",
|
||||
"description": "Control Tuya devices locally via MQTT",
|
||||
"homepage": "https://github.com/TheAgentK/tuya-mqtt#readme",
|
||||
"main": "tuya-mqtt.js",
|
||||
@@ -13,14 +13,14 @@
|
||||
},
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@tuyapi/cli": "^1.13.4",
|
||||
"@tuyapi/cli": "^1.13.6",
|
||||
"color-convert": "^2.0.1",
|
||||
"debug": "^4.1.1",
|
||||
"debug": "^4.3.1",
|
||||
"json5": "^2.1.3",
|
||||
"mqtt": "^4.2.1",
|
||||
"supports-color": "^7.2.0",
|
||||
"tuyapi": "^6.0.1",
|
||||
"mathjs": "7.5.1"
|
||||
"mqtt": "^4.2.6",
|
||||
"supports-color": "^8.1.0",
|
||||
"tuyapi": "^6.1.2",
|
||||
"mathjs": "8.1.1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user