Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* This script generates a device page
*/
const utils = require('./utils');
const notes = require('./device_page_notes');
const YAML = require('json2yaml');
const HomeassistantExtension = require('zigbee2mqtt/lib/extension/homeassistant');
const homeassistant = new HomeassistantExtension(null, null, null, null);
const assert = require('assert');
const devices = require('zigbee2mqtt/node_modules/zigbee-herdsman-converters').devices;
function generate(device) {
// verify that all model and notModel exist;
for (const note of notes) {
const check = (attr) => {
if (note[attr]) {
if (typeof note[attr] === 'string') {
assert(devices.find((d) => d.model === note[attr]), note[attr]);
} else {
for (const m of note[attr]) {
assert(devices.find((d) => d.model === m), m);
}
}
}
};
let text = '';
text += '| Model | Description | Picture |\n';
text += '| ------------- | ------------- | -------------------------- |\n';
devices = new Map(devices.map((d) => [d.model, d]));
devices.forEach((d) => {
const image = utils.getImage(d.model);
// eslint-disable-next-line
text += `| [${d.model}](../devices/${utils.normalizeModel(d.model)}.md) | ${d.vendor} ${d.description} (${d.supports}) | ![${image}](${image}) |\n`;
});
return text;
};
// Generated devices text
let devicesText = '';
const vendors = Array.from(new Set(devices.map((d) => d.vendor)));
vendors.sort();
vendors.forEach((vendor) => {
devicesText += `### ${vendor}\n\n`;
devicesText += generateTable(devices.filter((d) => d.vendor === vendor));
devicesText += '\n';
});
// Insert into template
template = template.replace('[DEVICES]', devicesText);
module.exports = template;
const fs = require('fs');
const path = require('path');
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`);
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));
});
display: table !important;
}
.main-content table tr th:nth-child(1) {
width: 15%;
}
.main-content table tr th:nth-child(2) {
width: 60%;
}
.main-content table tr th:nth-child(3) {
width: 25%;
}
*NOTE: This file has been generated, do not edit this file manually!*
Currently **${devices.length}** devices are supported from **${vendorsCount}** different vendors.
In case you own a Zigbee device which is **NOT** listed here, please see
[How to support new devices](../how_tos/how_to_support_new_devices.md).
[DEVICES]
`;
const generateTable = (devices) => {
let text = '';
text += '| Model | Description | Picture |\n';
text += '| ------------- | ------------- | -------------------------- |\n';
devices = new Map(devices.map((d) => [d.model, d]));
devices.forEach((d) => {
const image = utils.getImage(d.model);
// eslint-disable-next-line
text += `| [${d.model}](../devices/${utils.normalizeModel(d.model)}.md) | ${d.vendor} ${d.description} (${d.supports}) | ![${image}](${image}) |\n`;
/**
* This script generates the supported devices page.
*/
const devices = require('zigbee2mqtt/node_modules/zigbee-herdsman-converters').devices;
const utils = require('./utils');
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
const vendorsCount = devices.map((d) => d.vendor).filter(onlyUnique).length;
let template = `---
---
# Supported devices
<style type="text/css">
.main-content table {
table-layout: fixed;
display: table !important;</style>
/**
* This script generates the supported devices page.
*/
const devices = require('zigbee2mqtt/node_modules/zigbee-herdsman-converters').devices;
const utils = require('./utils');
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
const vendorsCount = devices.map((d) => d.vendor).filter(onlyUnique).length;
let template = `---
---
# Supported devices
<style type="text/css">
.main-content table {
table-layout: fixed;
display: table !important;
}
.main-content table tr th:nth-child(1) {
width: 15%;
}
.main-content table tr th:nth-child(2) {
width: 60%;
}</style>
/**
* This script generates the integrating-with-homeassistant page.
*/
const devices = require('zigbee2mqtt/node_modules/zigbee-shepherd-converters').devices;
const HomeassistantExtension = require('zigbee2mqtt/lib/extension/homeassistant');
const homeassistant = new HomeassistantExtension(null, null, null, null);
const YAML = require('json2yaml');
let template = `# Home Assistant
*NOTE 1: This file has been generated, do not edit this file manually!*
*NOTE 2: If you are using the [Zigbee2mqtt Hass.io add-on](https://github.com/danielwelch/hassio-zigbee2mqtt)
use their documentation*
## MQTT discovery
**At least Home Assistant >= 0.84 is required!**
**NOTE:** Groups are not auto-discovered, see configuration below.
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';
vendors.forEach((vendor) => {
devicesText += `### ${vendor}\n\n`;
devicesText += generateTable(devices.filter((d) => d.vendor === vendor));
devicesText += '\n';
});