Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const devices = require('zigbee2mqtt/node_modules/zigbee-shepherd-converters').devices;
const utils = require('./utils');
const base = path.join(__dirname, '..', 'docs');
const supportDevices = require('./supported-devices');
const devicePage = require('./device_page');
fs.writeFileSync(path.join(base, 'information', 'supported_devices.md'), supportDevices);
// Clean devices directory
for (const file of fs.readdirSync(path.join(base, 'devices'))) {
fs.unlinkSync(path.join(base, 'devices', file));
}
devices.forEach((device) => {
const file = path.join(base, 'devices', `${utils.normalizeModel(device.model)}.md`);
fs.writeFileSync(file, devicePage.generate(device));
});
payload.command_topic = `zigbee2mqtt//${payload.command_topic_prefix}/set`;
} else {
payload.command_topic = `zigbee2mqtt//set`;
}
}
delete payload.command_topic_prefix;
let yml = YAML.stringify([payload]);
yml = yml.replace(/(-) \n {4}/g, '- ');
yml = yml.replace('---', `${device.type}:`);
return yml;
};
let configuration = '';
devices.forEach((device) => {
configuration += `### ${device.model}\n`;
configuration += `{% raw %}\n`;
configuration += '```yaml\n';
const configurations = homeassistant._getMapping()[device.model];
if (configurations) {
configurations.forEach((d, i) => {
configuration += homeassistantConfig(d);
if (configurations.length > 1 && i < configurations.length - 1) {
configuration += '\n';
}
});
configuration += '```\n';
configuration += '{% endraw %}\n\n';