Skip to content

Commit

Permalink
Catch more errors while downloading and close dialog when completed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Jan 14, 2024
1 parent 1c41110 commit 7c469c3
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/components/dialogs/hacs-download-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ export class HacsDonwloadDialog extends LitElement {
await this._fetchRepository();
}

websocketSubscription(this.hass, (data) => (this._error = data), HacsDispatchEvent.ERROR);
websocketSubscription(
this.hass,
(data) => {
this._error = data;
this._installing = false;
},
HacsDispatchEvent.ERROR,
);
await this.updateComplete;
}

Expand All @@ -65,7 +72,7 @@ export class HacsDonwloadDialog extends LitElement {

private _getInstallPath = memoizeOne((repository: RepositoryBase) => {
let path: string = repository.local_path;
if (["template", "theme"].includes(repository.category)) {
if (["template", "theme", "python_script"].includes(repository.category)) {
path = `${path}/${repository.file_name}`;
}
return path;
Expand Down Expand Up @@ -223,6 +230,7 @@ export class HacsDonwloadDialog extends LitElement {

private async _installRepository(): Promise<void> {
this._installing = true;
this._error = undefined;
if (!this._repository) {
return;
}
Expand All @@ -232,11 +240,19 @@ export class HacsDonwloadDialog extends LitElement {
this._repository.available_version ||
this._repository.default_branch;

await repositoryDownloadVersion(
this.hass,
String(this._repository.id),
this._repository?.version_or_commit !== "commit" ? selectedVersion : undefined,
);
try {
await repositoryDownloadVersion(
this.hass,
String(this._repository.id),
this._repository?.version_or_commit !== "commit" ? selectedVersion : undefined,
);
} catch (err: any) {
this._error = err || {
message: "Could not download repository, check core logs for more information.",
};
this._installing = false;
return;
}

this._dialogParams!.hacs.log.debug(this._repository.category, "_installRepository");
this._dialogParams!.hacs.log.debug(
Expand Down Expand Up @@ -264,6 +280,9 @@ export class HacsDonwloadDialog extends LitElement {
},
});
}
if (this._error === undefined) {
this.closeDialog();
}
}

static get styles(): CSSResultGroup {
Expand Down

0 comments on commit 7c469c3

Please sign in to comment.