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',