mirror of
https://github.com/lehanspb/tuya-mqtt.git
synced 2025-12-18 08:13:23 +00:00
Minor enhancements
* Properly disconnect from devices on exit * Monitor for Home Assistant status and resend discovery
This commit is contained in:
@@ -5,12 +5,16 @@ const utils = require('../lib/utils')
|
||||
|
||||
class RGBTWLight extends TuyaDevice {
|
||||
async init() {
|
||||
await this.guessLightInfo()
|
||||
// If no manual config try to detect device settings
|
||||
if (!this.config.dpsPower) {
|
||||
await this.guessLightInfo()
|
||||
}
|
||||
|
||||
// If detection failed and no manual config return without initializing
|
||||
if (!this.guess.dpsPower && !this.config.dpsPower) {
|
||||
debug('Automatic discovery of Tuya bulb settings failed and no manual configuration')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Set device specific variables
|
||||
this.config.dpsPower = this.config.dpsPower ? this.config.dpsPower : this.guess.dpsPower
|
||||
@@ -25,7 +29,6 @@ class RGBTWLight extends TuyaDevice {
|
||||
this.config.colorType = this.config.colorType ? this.config.colorType : this.guess.colorType
|
||||
|
||||
this.deviceData.mdl = 'RGBTW Light'
|
||||
|
||||
this.isRgbtwLight = true
|
||||
|
||||
// Map generic DPS topics to device specific topic names
|
||||
@@ -66,7 +69,7 @@ class RGBTWLight extends TuyaDevice {
|
||||
|
||||
// If device supports Color Temperature add color temp device topic
|
||||
if (this.config.dpsColorTemp) {
|
||||
// Values used for tranform
|
||||
// Values used for tranforming from 1-255 scale to mireds range
|
||||
const rangeFactor = (this.config.maxColorTemp-this.config.minColorTemp)/100
|
||||
const scaleFactor = this.config.colorTempScale/100
|
||||
const tuyaMaxColorTemp = this.config.maxColorTemp/rangeFactor*scaleFactor
|
||||
@@ -104,6 +107,9 @@ class RGBTWLight extends TuyaDevice {
|
||||
white_value_state_topic: this.baseTopic+'white_brightness_state',
|
||||
white_value_command_topic: this.baseTopic+'white_brightness_command',
|
||||
white_value_scale: 100,
|
||||
availability_topic: this.baseTopic+'status',
|
||||
payload_available: 'online',
|
||||
payload_not_available: 'offline',
|
||||
unique_id: this.config.id,
|
||||
device: this.deviceData
|
||||
}
|
||||
|
||||
@@ -44,6 +44,9 @@ class SimpleDimmer extends TuyaDevice {
|
||||
command_topic: this.baseTopic+'command',
|
||||
brightness_state_topic: this.baseTopic+'brightness_state',
|
||||
brightness_command_topic: this.baseTopic+'brightness_command',
|
||||
availability_topic: this.baseTopic+'status',
|
||||
payload_available: 'online',
|
||||
payload_not_available: 'offline',
|
||||
unique_id: this.config.id,
|
||||
device: this.deviceData
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ class SimpleSwitch extends TuyaDevice {
|
||||
name: (this.config.name) ? this.config.name : this.config.id,
|
||||
state_topic: this.baseTopic+'state',
|
||||
command_topic: this.baseTopic+'command',
|
||||
availability_topic: this.baseTopic+'status',
|
||||
payload_available: 'online',
|
||||
payload_not_available: 'offline',
|
||||
unique_id: this.config.id,
|
||||
device: this.deviceData
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const TuyAPI = require('tuyapi')
|
||||
const { evaluate } = require('mathjs')
|
||||
const utils = require('../lib/utils')
|
||||
const { msSleep } = require('../lib/utils')
|
||||
const debug = require('debug')('tuya-mqtt:tuyapi')
|
||||
const debugState = require('debug')('tuya-mqtt:state')
|
||||
const debugCommand = require('debug')('tuya-mqtt:command')
|
||||
|
||||
Reference in New Issue
Block a user