Skip to content

Commit

Permalink
Fix offline db migration support (#21452)
Browse files Browse the repository at this point in the history
* Fix offline db migration support

* Add error handling
  • Loading branch information
emontnemery authored Jul 23, 2024
1 parent 87ba0e7 commit 79618ce
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/layouts/home-assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,24 +200,26 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
}

protected async checkDataBaseMigration() {
if (this.hass?.config?.components.includes("recorder")) {
let recorderInfoProm: Promise<RecorderInfo> | undefined;
const preloadWindow = window as WindowWithPreloads;
// On first load, we speed up loading page by having recorderInfoProm ready
if (preloadWindow.recorderInfoProm) {
recorderInfoProm = preloadWindow.recorderInfoProm;
preloadWindow.recorderInfoProm = undefined;
}
const info = await (recorderInfoProm ||
getRecorderInfo(this.hass.connection));
this._databaseMigration =
info.migration_in_progress && !info.migration_is_live;
if (this._databaseMigration) {
// check every 5 seconds if the migration is done
setTimeout(() => this.checkDataBaseMigration(), 5000);
}
} else {
this._databaseMigration = false;
let recorderInfoProm: Promise<RecorderInfo> | undefined;
const preloadWindow = window as WindowWithPreloads;
// On first load, we speed up loading page by having recorderInfoProm ready
if (preloadWindow.recorderInfoProm) {
recorderInfoProm = preloadWindow.recorderInfoProm;
preloadWindow.recorderInfoProm = undefined;
}
const info = await (
recorderInfoProm || getRecorderInfo(this.hass!.connection)
).catch((err) => {
// If the command failed with code unknown_command, recorder is not enabled,
// otherwise re-throw the error
if (err.code !== "unknown_command") throw err;
return { migration_in_progress: false, migration_is_live: false };
});
this._databaseMigration =
info.migration_in_progress && !info.migration_is_live;
if (this._databaseMigration) {
// check every 5 seconds if the migration is done
setTimeout(() => this.checkDataBaseMigration(), 5000);
}
}

Expand Down

0 comments on commit 79618ce

Please sign in to comment.