diff --git a/src/components/dialogs/hacs-download-dialog.ts b/src/components/dialogs/hacs-download-dialog.ts index 6c51ba85..c25a2acb 100644 --- a/src/components/dialogs/hacs-download-dialog.ts +++ b/src/components/dialogs/hacs-download-dialog.ts @@ -41,6 +41,8 @@ export class HacsDonwloadDialog extends LitElement { @state() _dialogParams?: HacsDownloadDialogParams; + @state() _selectedVersion?: string; + public async showDialog(dialogParams: HacsDownloadDialogParams): Promise { this._dialogParams = dialogParams; this._waiting = false; @@ -50,6 +52,10 @@ export class HacsDonwloadDialog extends LitElement { await this._fetchRepository(); } + if (this._repository && this._repository.version_or_commit !== "commit") { + this._selectedVersion = this._repository.available_version; + } + websocketSubscription( this.hass, (data) => { @@ -127,7 +133,7 @@ export class HacsDonwloadDialog extends LitElement { .data=${this._repository.version_or_commit === "version" ? { beta: this._repository.beta, - version: this._repository.releases[0], + version: this._selectedVersion, } : {}} .schema=${donwloadRepositorySchema} @@ -221,6 +227,7 @@ export class HacsDonwloadDialog extends LitElement { this._dialogParams!.repositoryId, ev.detail.value.version, ); + this._selectedVersion = ev.detail.value.version; } if (updateNeeded) { await this._fetchRepository(); @@ -229,12 +236,28 @@ export class HacsDonwloadDialog extends LitElement { } private async _installRepository(): Promise { - this._installing = true; - this._error = undefined; if (!this._repository) { return; } + if (this._waiting) { + this._error = "Waiting to update repository information, try later."; + return; + } + + if (this._installing) { + this._error = "Already installing, please wait."; + return; + } + + if (!this._repository.can_download) { + this._error = "Can not download this repository."; + return; + } + + this._installing = true; + this._error = undefined; + const selectedVersion = this._repository.selected_tag || this._repository.available_version || @@ -244,7 +267,7 @@ export class HacsDonwloadDialog extends LitElement { await repositoryDownloadVersion( this.hass, String(this._repository.id), - this._repository?.version_or_commit !== "commit" ? selectedVersion : undefined, + this._repository?.version_or_commit !== "commit" ? this._selectedVersion : undefined, ); } catch (err: any) { this._error = err || {