mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-16 02:18:31 -07:00
Fix crash when removing device from group which has no devices in settings. #3185
This commit is contained in:
parent
dfc897af1a
commit
5cd1af569e
@ -591,6 +591,9 @@ function removeDeviceFromGroup(groupIDorName, keys) {
|
|||||||
const groupID = getGroupThrowIfNotExists(groupIDorName).ID;
|
const groupID = getGroupThrowIfNotExists(groupIDorName).ID;
|
||||||
const settings = get();
|
const settings = get();
|
||||||
const group = settings.groups[groupID];
|
const group = settings.groups[groupID];
|
||||||
|
if (!group.devices) {
|
||||||
|
group.devices = [];
|
||||||
|
}
|
||||||
|
|
||||||
const key = groupHasDevice(group, keys);
|
const key = groupHasDevice(group, keys);
|
||||||
if (key) {
|
if (key) {
|
||||||
|
@ -434,6 +434,31 @@ describe('Settings', () => {
|
|||||||
expect(settings.get().groups).toStrictEqual(expected);
|
expect(settings.get().groups).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should crash when removing device from group when group has no devices', () => {
|
||||||
|
write(configurationFile, {
|
||||||
|
devices: {
|
||||||
|
'0x123': {
|
||||||
|
friendly_name: 'bulb',
|
||||||
|
retain: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
groups: {
|
||||||
|
'1': {
|
||||||
|
friendly_name: 'test123',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
settings.removeDeviceFromGroup('test123', ['0x123']);
|
||||||
|
const expected = {
|
||||||
|
'1': {
|
||||||
|
friendly_name: 'test123',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(settings.get().groups).toStrictEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('Should throw when adding device to non-existing group', () => {
|
it('Should throw when adding device to non-existing group', () => {
|
||||||
write(configurationFile, {
|
write(configurationFile, {
|
||||||
devices: {
|
devices: {
|
||||||
|
Loading…
Reference in New Issue
Block a user