Use js-yaml as yaml parser instead of yawn-yaml. #64

This commit is contained in:
Koenkk committed 2018-05-25 16:42:29 +02:00
1 parent 312ed033db
commit 08f3f96d73
3 files changed
+15 -66

No files matched your search

+10 -23
View File
@@ -1,48 +1,35 @@
const YAWN = require('yawn-yaml/cjs');
const yaml = require('js-yaml');
const fs = require('fs');
const data = require('./data');
const file = data.joinPath('configuration.yaml');
let yawn = read();
let settings = read();
function writeRead() {
write();
yawn = read();
settings = read();
}
function write() {
fs.writeFileSync(file, yawn.yaml);
fs.writeFileSync(file, yaml.safeDump(settings));
}
function read() {
return new YAWN(fs.readFileSync(file, 'utf8'));
return yaml.safeLoad(fs.readFileSync(file, 'utf8'));
}
function addDevice(id) {
if (!yawn.json.devices) {
const first = '\n' +
'# List of devices, automatically updates when new devices join, E.G.:\n' +
`# '0x00158d0001d8e1d2':\n` +
'# friendly_name: bedroom_switch # Friendly name to be used in MQTT topic\n' +
'# retain: true # Retain MQTT messages\n' +
'devices:\n' +
` '${id}':\n` +
` friendly_name: '${id}'\n` +
` retain: false`;
yawn.yaml += first;
} else {
const devices = yawn.json.devices;
devices[id] = {friendly_name: id, retain: false};
yawn.json = {...yawn.json, devices: devices};
if (!settings.devices) {
settings.devices = {};
}
settings.devices[id] = {friendly_name: id, retain: false};
writeRead();
}
module.exports = {
get: () => yawn.json,
get: () => settings,
write: () => write(),
getDevice: (id) => yawn.json.devices ? yawn.json.devices[id] : false,
getDevice: (id) => settings.devices ? settings.devices[id] : false,
addDevice: (id) => addDevice(id),
};
+4 -42
View File
@@ -559,14 +559,6 @@
"strip-json-comments": "2.0.1",
"table": "4.0.2",
"text-table": "0.2.0"
},
"dependencies": {
"lodash": {
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==",
"dev": true
}
}
},
"eslint-config-google": {
@@ -883,14 +875,6 @@
"string-width": "2.1.1",
"strip-ansi": "4.0.0",
"through": "2.3.8"
},
"dependencies": {
"lodash": {
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==",
"dev": true
}
}
},
"is-absolute": {
@@ -1094,9 +1078,10 @@
}
},
"lodash": {
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz",
"integrity": "sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y="
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==",
"dev": true
},
"lru-cache": {
"version": "4.1.3",
@@ -2565,14 +2550,6 @@
"lodash": "4.17.10",
"slice-ansi": "1.0.0",
"string-width": "2.1.1"
},
"dependencies": {
"lodash": {
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==",
"dev": true
}
}
},
"text-table": {
@@ -2751,21 +2728,6 @@
"integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=",
"dev": true
},
"yaml-js": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/yaml-js/-/yaml-js-0.1.5.tgz",
"integrity": "sha1-oBNpAQs1WNiq7SOUYV39B4D9j6w="
},
"yawn-yaml": {
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/yawn-yaml/-/yawn-yaml-1.3.4.tgz",
"integrity": "sha1-FMUaGUAkJJwi9TS20lQaVNCryt0=",
"requires": {
"js-yaml": "3.11.0",
"lodash": "3.10.1",
"yaml-js": "0.1.5"
}
},
"zcl-id": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/zcl-id/-/zcl-id-0.3.2.tgz",
+1 -1
View File
@@ -35,7 +35,7 @@
"zigbee-shepherd": "git+https://github.com/Koenkk/zigbee-shepherd.git",
"zigbee-shepherd-converters": "*",
"json2yaml": "*",
"yawn-yaml": "*"
"js-yaml": "*"
},
"devDependencies": {
"eslint": "*",