mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-17 02:48:31 -07:00
Add settings.set api.
This commit is contained in:
parent
ba77860489
commit
cc45413e2d
@ -75,6 +75,25 @@ function read() {
|
||||
return yaml.safeLoad(fs.readFileSync(file, 'utf8'));
|
||||
}
|
||||
|
||||
function set(path, value) {
|
||||
let obj = settings;
|
||||
|
||||
for (let i = 0; i < path.length; i++) {
|
||||
const key = path[i];
|
||||
if (i === path.length - 1) {
|
||||
obj[key] = value;
|
||||
} else {
|
||||
if (!obj[key]) {
|
||||
obj[key] = {};
|
||||
}
|
||||
|
||||
obj = obj[key];
|
||||
}
|
||||
}
|
||||
|
||||
writeRead();
|
||||
}
|
||||
|
||||
function addDevice(ieeeAddr) {
|
||||
if (!settings.devices) {
|
||||
settings.devices = {};
|
||||
@ -126,6 +145,7 @@ function changeFriendlyName(old, new_) {
|
||||
module.exports = {
|
||||
get: () => objectAssignDeep.noMutate(defaults, settings),
|
||||
write: () => write(),
|
||||
set: (path, value) => set(path, value),
|
||||
|
||||
getDevice: (ieeeAddr) => settings.devices ? settings.devices[ieeeAddr] : null,
|
||||
getGroup: (ID) => settings.groups ? settings.groups[ID]: null,
|
||||
|
Loading…
Reference in New Issue
Block a user