mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-29 07:08:56 +00:00
fix(ignore): Fix 2 to 3 migration enabling frontend/availabilty/homeassistant when not set (#25349)
This commit is contained in:
@@ -86,16 +86,17 @@ function setValue(currentSettings: any, path: string[], value: unknown, createPa
|
||||
function getValue(currentSettings: any, path: string[]): [validPath: boolean, value: unknown] {
|
||||
for (let i = 0; i < path.length; i++) {
|
||||
const key = path[i];
|
||||
const value = currentSettings[key];
|
||||
|
||||
if (i === path.length - 1) {
|
||||
return [true, currentSettings[key]];
|
||||
return [value !== undefined, value];
|
||||
} else {
|
||||
if (!currentSettings[key]) {
|
||||
if (!value) {
|
||||
// invalid path
|
||||
break;
|
||||
}
|
||||
|
||||
currentSettings = currentSettings[key];
|
||||
currentSettings = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -807,6 +807,36 @@ describe('Settings Migration', () => {
|
||||
expect(migrationNotesContent).toContain(`[SPECIAL] Property 'frontend' is now always an object.`);
|
||||
expect(migrationNotesContent).toContain(`[SPECIAL] Property 'availability' is now always an object.`);
|
||||
});
|
||||
|
||||
it('Update when not set, tests that frontend/availability is not added when not set', () => {
|
||||
// @ts-expect-error workaround
|
||||
const beforeSettings = objectAssignDeep.noMutate({}, settings.getPersistedSettings());
|
||||
// @ts-expect-error workaround
|
||||
const afterSettings = objectAssignDeep.noMutate({}, settings.getPersistedSettings());
|
||||
afterSettings.version = 3;
|
||||
afterSettings.homeassistant = {enabled: false};
|
||||
|
||||
settings.set(['homeassistant'], false);
|
||||
|
||||
expect(settings.getPersistedSettings()).toStrictEqual(
|
||||
// @ts-expect-error workaround
|
||||
objectAssignDeep.noMutate(beforeSettings, {
|
||||
homeassistant: false,
|
||||
}),
|
||||
);
|
||||
|
||||
settingsMigration.migrateIfNecessary();
|
||||
|
||||
const migratedSettings = settings.getPersistedSettings();
|
||||
|
||||
expect(migratedSettings).toStrictEqual(afterSettings);
|
||||
const migrationNotes = mockedData.joinPath('migration-2-to-3.log');
|
||||
expect(existsSync(migrationNotes)).toStrictEqual(true);
|
||||
const migrationNotesContent = readFileSync(migrationNotes, 'utf8');
|
||||
expect(migrationNotesContent).toContain(`[SPECIAL] Property 'homeassistant' is now always an object.`);
|
||||
expect(migrationNotesContent).not.toContain(`[SPECIAL] Property 'frontend' is now always an object.`);
|
||||
expect(migrationNotesContent).not.toContain(`[SPECIAL] Property 'availability' is now always an object.`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Migrates v3 to v4', () => {
|
||||
|
||||
Reference in New Issue
Block a user