3.0.0-beta2

* Implement basic template model
* Generic device can specify template in devices.conf
* Simple switch, dimmer, and RGBTW specific support files
This commit is contained in:
tsightler
2020-10-02 23:16:53 -04:00
parent 56b87aa27e
commit f598d246cf
11 changed files with 750 additions and 989 deletions

30
devices/generic-device.js Normal file
View File

@@ -0,0 +1,30 @@
const TuyaDevice = require('./tuya-device')
const debug = require('debug')('tuya-mqtt:tuya')
const utils = require('../lib/utils')
class GenericDevice extends TuyaDevice {
async init() {
this.deviceData.mdl = 'Generic Device'
// Check if custom template in device config
if (this.config.hasOwnProperty('template')) {
// Map generic DPS topics to device specific topic names
this.deviceTopics = this.config.template
console.log(this.deviceTopics)
} else {
// Try to get schema to at least know what DPS keys to get initial update
const result = await this.device.get({"schema": true})
if (!utils.isJsonString(result)) {
if (result === 'Schema for device not available') {
debug('Device id '+this.config.id+' failed schema discovery and no custom template defined')
debug('Cannot get initial DPS state data for device '+this.options.name+' but data updates will be publish')
}
}
}
// Get initial states and start publishing topics
this.getStates()
}
}
module.exports = GenericDevice