From 21dadd631c28326ecbc91a87001969e454ef2cbc Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Mon, 16 Sep 2019 19:49:49 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20throw=20error=20when=20devices?= =?UTF-8?q?=20is=20null.=20https://github.com/Koenkk/zigbee2mqtt/issues/19?= =?UTF-8?q?73?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/util/settings.js | 10 ++++++++-- test/settings.test.js | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/util/settings.js b/lib/util/settings.js index ca45f54d..5d57ef74 100644 --- a/lib/util/settings.js +++ b/lib/util/settings.js @@ -14,8 +14,6 @@ const defaults = { serial: { disable_led: false, }, - devices: {}, - groups: {}, device_options: {}, map_options: { graphviz: { @@ -158,6 +156,14 @@ function getWithDefaults() { _settingsWithDefaults = objectAssignDeep.noMutate(defaults, get()); } + if (!_settingsWithDefaults.devices) { + _settingsWithDefaults.devices = {}; + } + + if (!_settingsWithDefaults.groups) { + _settingsWithDefaults.groups = {}; + } + return _settingsWithDefaults; } diff --git a/test/settings.test.js b/test/settings.test.js index 62940bcb..67655114 100644 --- a/test/settings.test.js +++ b/test/settings.test.js @@ -78,6 +78,12 @@ describe('Settings', () => { expect(device).toStrictEqual(expected); }); + it('Should not throw error when devices is null', () => { + const content = {devices: null}; + write(configurationFile, content); + settings.getDevice('0x12345678'); + }); + it('Should read devices form a separate file', () => { const contentConfiguration = { devices: 'devices.yaml',