Skip to content

Commit

Permalink
Fix version selector (#726)
Browse files Browse the repository at this point in the history
* Fix version selector

* Actually fix it
  • Loading branch information
ludeeus authored May 23, 2024
1 parent 06bf2ed commit eca70bb
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/components/dialogs/hacs-download-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class HacsDonwloadDialog extends LitElement {

@state() _dialogParams?: HacsDownloadDialogParams;

@state() _selectedVersion?: string;

public async showDialog(dialogParams: HacsDownloadDialogParams): Promise<void> {
this._dialogParams = dialogParams;
this._waiting = false;
Expand All @@ -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) => {
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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();
Expand All @@ -229,12 +236,28 @@ export class HacsDonwloadDialog extends LitElement {
}

private async _installRepository(): Promise<void> {
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 ||
Expand All @@ -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 || {
Expand Down

0 comments on commit eca70bb

Please sign in to comment.