zigbee2mqtt/lib/extension/externalConverters.js
2020-06-29 16:17:11 +02:00

32 lines
1.1 KiB
JavaScript

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]);
}
const converter = require(converterModule);
if (Array.isArray(converter)) {
converter.forEach((mod) => {
zigbeeHerdsmanConverters.addDeviceDefinition(mod);
});
} else {
zigbeeHerdsmanConverters.addDeviceDefinition(converter);
}
});
}
}
module.exports = ExternalConverters;