3.0.1 Update
* Script to merge device additions and changes into devices.conf (#49)
* Fix typos in README.md
* Add republish on reconnect
* Filter additional invalid characters '+','#','/' from topic line (replace with '_')
* Minor bugfixes for parse values
* Include script for merging new devices into existing config
* Update dependency

Co-authored-by: tsightler <tsightler@gmail.com>
Co-authored-by: Doug Krahmer <doug.git@remhark.com>
This commit is contained in:
tsightler
2020-12-23 20:10:29 -05:00
committed by GitHub
parent bda39b03b4
commit 44a5c6adbf
9 changed files with 156 additions and 56 deletions

View File

@@ -17,7 +17,7 @@ class TuyaDevice {
id: this.config.id,
key: this.config.key
}
if (this.config.name) { this.options.name = this.config.name.toLowerCase().replace(/ /g,'_') }
if (this.config.name) { this.options.name = this.config.name.toLowerCase().replace(/\s|\+|#|\//g,'_') }
if (this.config.ip) {
this.options.ip = this.config.ip
if (this.config.version) {
@@ -249,10 +249,10 @@ class TuyaDevice {
// Perform any required math transforms before returing command value
switch (deviceTopic.type) {
case 'int':
value = (deviceTopic.stateMath) ? parseInt(Math.round(evaluate(value+deviceTopic.stateMath))) : value = parseInt(value)
value = (deviceTopic.stateMath) ? parseInt(Math.round(evaluate(value+deviceTopic.stateMath))) : parseInt(value)
break;
case 'float':
value = (deviceTopic.stateMath) ? parseFloat(evaluate(value+deviceTopic.stateMath)) : value = parseFloat(value)
value = (deviceTopic.stateMath) ? parseFloat(evaluate(value+deviceTopic.stateMath)) : parseFloat(value)
break;
}
@@ -601,6 +601,14 @@ class TuyaDevice {
if (this.connected) { return }
this.connectDevice()
}
// 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()
}
// Simple function to monitor heartbeats to determine if
monitorHeartbeat() {