mirror of
https://github.com/lehanspb/tuya-mqtt.git
synced 2025-12-16 17:54:36 +00:00
3.0.0-beta3
* Improve RGBTW white/color logic * Rebase MQTT topic brightess to 100 scale (vs 255/1000) * Added based auto-discovery for RGBTW light * Added math functions
This commit is contained in:
@@ -4,14 +4,17 @@ const utils = require('../lib/utils')
|
||||
|
||||
class RGBTWLight extends TuyaDevice {
|
||||
async init() {
|
||||
await this.guessLightInfo()
|
||||
|
||||
// Set device specific variables
|
||||
this.config.dpsPower = this.config.dpsPower ? this.config.dpsPower : 1
|
||||
this.config.dpsMode = this.config.dpsMode ? this.config.dpsMode : 2
|
||||
this.config.dpsWhiteValue = this.config.dpsWhiteValue ? this.config.dpsWhiteValue : 3
|
||||
this.config.whiteValueScale = this.config.whiteValueScale ? this.config.whiteValueScale : 1000
|
||||
this.config.dpsColorTemp = this.config.dpsColorTemp ? this.config.dpsColorTemp : 4
|
||||
this.config.dpsColor = this.config.dpsColor ? this.config.dpsColor : 5
|
||||
this.config.colorType = this.config.colorType ? this.config.colorType : 'hsbhex'
|
||||
this.config.dpsPower = this.config.dpsPower ? this.config.dpsPower : this.guess.dpsPower
|
||||
this.config.dpsMode = this.config.dpsMode ? this.config.dpsMode : this.guess.dpsMode
|
||||
this.config.dpsWhiteValue = this.config.dpsWhiteValue ? this.config.dpsWhiteValue : this.guess.dpsWhiteValue
|
||||
this.config.whiteValueScale = this.config.whiteValueScale ? this.config.whiteValueScale : this.guess.whiteValueScale
|
||||
this.config.dpsColorTemp = this.config.dpsColorTemp ? this.config.dpsColorTemp : this.guess.dpsColorTemp
|
||||
this.config.dpsColor = this.config.dpsColor ? this.config.dpsColor : this.guess.dpsColor
|
||||
this.config.colorType = this.config.colorType ? this.config.colorType : this.guess.colorType
|
||||
this.config.colorType = 'hsb'
|
||||
|
||||
this.deviceData.mdl = 'RGBTW Light'
|
||||
|
||||
@@ -26,9 +29,11 @@ class RGBTWLight extends TuyaDevice {
|
||||
white_value_state: {
|
||||
key: this.config.dpsWhiteValue,
|
||||
type: 'int',
|
||||
min: (this.config.whiteValueScale == 1000) ? 10 : 1,
|
||||
max: this.config.whiteValueScale,
|
||||
scale: this.config.whiteValueScale
|
||||
min: 1,
|
||||
max: 100,
|
||||
scale: this.config.whiteValueScale,
|
||||
stateMath: (this.config.whiteValueScale == 1000) ? '/10' : '/2.55',
|
||||
commandMath: (this.config.whiteValueScale == 1000) ? '*10' : '*2.55'
|
||||
},
|
||||
hs_state: {
|
||||
key: this.config.dpsColor,
|
||||
@@ -68,12 +73,12 @@ class RGBTWLight extends TuyaDevice {
|
||||
command_topic: this.baseTopic+'command',
|
||||
brightness_state_topic: this.baseTopic+'brightness_state',
|
||||
brightness_command_topic: this.baseTopic+'brightness_command',
|
||||
brightness_scale: 1000,
|
||||
brightness_scale: 100,
|
||||
hs_state_topic: this.baseTopic+'hs_state',
|
||||
hs_command_topic: this.baseTopic+'hs_command',
|
||||
white_value_state_topic: this.baseTopic+'white_value_state',
|
||||
white_value_command_topic: this.baseTopic+'white_value_command',
|
||||
white_value_scale: 1000,
|
||||
white_value_scale: 100,
|
||||
unique_id: this.config.id,
|
||||
device: this.deviceData
|
||||
}
|
||||
@@ -82,6 +87,41 @@ class RGBTWLight extends TuyaDevice {
|
||||
debug(discoveryData)
|
||||
this.publishMqtt(configTopic, JSON.stringify(discoveryData))
|
||||
}
|
||||
|
||||
async guessLightInfo() {
|
||||
this.guess = new Object()
|
||||
let mode = await this.device.get({"dps": 2})
|
||||
if (mode && (mode === 'white' || mode === 'colour')) {
|
||||
this.guess.dpsPower = 1
|
||||
this.guess.dpsMode = 2
|
||||
this.guess.dpsWhiteValue = 3
|
||||
this.guess.whiteValueScale = 255
|
||||
const colorTemp = await this.device.get({"dps": 4})
|
||||
if (colorTemp) {
|
||||
this.guess.dpsColorTemp = 4
|
||||
} else {
|
||||
this.guess.dpsColorTemp = 0
|
||||
}
|
||||
this.guess.dpsColor = 5
|
||||
const color = await this.device.get({"dps": this.guess.dpsColor})
|
||||
this.guess.colorType = (color && color.length === 14) ? 'hsbhex' : 'hsb'
|
||||
} else {
|
||||
mode = await this.device.get({"dps": 20})
|
||||
this.guess.dpsPower = 20
|
||||
this.guess.dpsMode = 21
|
||||
this.guess.dpsWhiteValue = 22
|
||||
this.guess.whiteValueScale = 1000
|
||||
const colorTemp = await this.device.get({"dps": 23})
|
||||
if (colorTemp) {
|
||||
this.guess.dpsColorTemp = 23
|
||||
} else {
|
||||
this.guess.dpsColorTemp = 0
|
||||
}
|
||||
this.guess.dpsColor = 24
|
||||
const color = await this.device.get({"dps": this.guess.dpsColor})
|
||||
this.guess.colorType = (color && color.length === 12) ? 'hsb' : 'hsbhex'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RGBTWLight
|
||||
Reference in New Issue
Block a user