2020-06-29 07:16:16 -07:00
|
|
|
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
|
|
|
|
const settings = require('../util/settings');
|
|
|
|
const Extension = require('./extension');
|
|
|
|
const data = require('../util/data');
|
|
|
|
|
|
|
|
class ExternalConverters extends Extension {
|
|
|
|
constructor(zigbee, mqtt, state, publishEntityState, eventBus) {
|
|
|
|
super(zigbee, mqtt, state, publishEntityState, eventBus);
|
|
|
|
|
|
|
|
const externalConverters = settings.get().external_converters;
|
|
|
|
|
|
|
|
externalConverters.forEach((moduleName) => {
|
|
|
|
let converterModule = moduleName;
|
|
|
|
|
|
|
|
if (moduleName.endsWith('.js')) {
|
|
|
|
converterModule = data.joinPath(moduleName.split('.')[0]);
|
|
|
|
}
|
2020-06-29 07:17:11 -07:00
|
|
|
|
2020-06-29 07:16:16 -07:00
|
|
|
const converter = require(converterModule);
|
|
|
|
if (Array.isArray(converter)) {
|
|
|
|
converter.forEach((mod) => {
|
|
|
|
zigbeeHerdsmanConverters.addDeviceDefinition(mod);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
zigbeeHerdsmanConverters.addDeviceDefinition(converter);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ExternalConverters;
|