diff --git a/custom_components/bahmcloud_store/panel/panel.js b/custom_components/bahmcloud_store/panel/panel.js index 17dd9da..9ac4440 100644 --- a/custom_components/bahmcloud_store/panel/panel.js +++ b/custom_components/bahmcloud_store/panel/panel.js @@ -45,6 +45,11 @@ class BahmcloudStorePanel extends HTMLElement { this._restoreSelected = ""; this._restoring = false; this._restoreError = null; + + // Phase C1: selectable install version + this._versionsCache = {}; // repo_id -> [{ref,label,source}, ...] + this._versionsLoadingRepoId = null; + this._selectedVersionByRepoId = {}; // repo_id -> ref ("" means latest) } set hass(hass) { @@ -114,7 +119,13 @@ class BahmcloudStorePanel extends HTMLElement { this._update(); try { - const resp = await this._hass.callApi("post", `bcs/install?repo_id=${encodeURIComponent(repoId)}`, {}); + const sel = this._safeText(this._selectedVersionByRepoId?.[repoId] || "").trim(); + const qv = sel ? `&version=${encodeURIComponent(sel)}` : ""; + const resp = await this._hass.callApi( + "post", + `bcs/install?repo_id=${encodeURIComponent(repoId)}${qv}`, + {}, + ); if (!resp?.ok) { this._error = this._safeText(resp?.message) || "Install failed."; } else { @@ -140,7 +151,13 @@ class BahmcloudStorePanel extends HTMLElement { this._update(); try { - const resp = await this._hass.callApi("post", `bcs/update?repo_id=${encodeURIComponent(repoId)}`, {}); + const sel = this._safeText(this._selectedVersionByRepoId?.[repoId] || "").trim(); + const qv = sel ? `&version=${encodeURIComponent(sel)}` : ""; + const resp = await this._hass.callApi( + "post", + `bcs/update?repo_id=${encodeURIComponent(repoId)}${qv}`, + {}, + ); if (!resp?.ok) { this._error = this._safeText(resp?.message) || "Update failed."; } else { @@ -366,8 +383,41 @@ class BahmcloudStorePanel extends HTMLElement { this._readmeExpanded = false; this._readmeCanToggle = false; + // Versions dropdown + if (!(repoId in this._selectedVersionByRepoId)) { + this._selectedVersionByRepoId[repoId] = ""; // default = latest + } + this._update(); this._loadReadme(repoId); + this._loadVersions(repoId); + } + + async _loadVersions(repoId) { + if (!this._hass) return; + if (!repoId) return; + + // Cache: avoid re-fetching repeatedly in the same session. + if (Array.isArray(this._versionsCache?.[repoId]) && this._versionsCache[repoId].length) { + return; + } + + this._versionsLoadingRepoId = repoId; + this._update(); + + try { + const resp = await this._hass.callApi("get", `bcs/versions?repo_id=${encodeURIComponent(repoId)}`); + if (resp?.ok && Array.isArray(resp.versions)) { + this._versionsCache[repoId] = resp.versions; + } else { + this._versionsCache[repoId] = []; + } + } catch (e) { + this._versionsCache[repoId] = []; + } finally { + this._versionsLoadingRepoId = null; + this._update(); + } } async _loadReadme(repoId) { @@ -953,6 +1003,8 @@ class BahmcloudStorePanel extends HTMLElement { const r = this._detailRepo; if (!r) return `