Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version selector #726

Merged
merged 2 commits into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
ludeeus marked this conversation as resolved.
Show resolved Hide resolved

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