Skip to content

Commit 797d2be

Browse files
authored
show spinner on update button (during update installation) (#26110)
* scroll to top when installing an update * Revert "scroll to top when installing an update" This reverts commit d0051b0. * add progress spinner to update button * refactor disabled logic for update/skip button * do not run update when disabled button is clicked * refactor: use new ha-button to show progress * refactor: move functions to update.ts
1 parent 99a91e1 commit 797d2be

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/data/update.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
HassEntityBase,
55
HassEvent,
66
} from "home-assistant-js-websocket";
7-
import { BINARY_STATE_ON } from "../common/const";
7+
import { BINARY_STATE_ON, BINARY_STATE_OFF } from "../common/const";
88
import { computeDomain } from "../common/entity/compute_domain";
99
import { computeStateDomain } from "../common/entity/compute_state_domain";
1010
import { supportsFeature } from "../common/entity/supports-feature";
@@ -52,6 +52,15 @@ export const updateCanInstall = (
5252
(showSkipped && Boolean(entity.attributes.skipped_version))) &&
5353
supportsFeature(entity, UpdateEntityFeature.INSTALL);
5454

55+
export const latestVersionIsSkipped = (entity: UpdateEntity): boolean =>
56+
!!(
57+
entity.attributes.latest_version &&
58+
entity.attributes.skipped_version === entity.attributes.latest_version
59+
);
60+
61+
export const updateButtonIsDisabled = (entity: UpdateEntity): boolean =>
62+
entity.state === BINARY_STATE_OFF && !latestVersionIsSkipped(entity);
63+
5564
export const updateIsInstalling = (entity: UpdateEntity): boolean =>
5665
!!entity.attributes.in_progress;
5766

src/dialogs/more-info/controls/more-info-update.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { relativeTime } from "../../../common/datetime/relative_time";
77
import { supportsFeature } from "../../../common/entity/supports-feature";
88
import "../../../components/ha-alert";
99
import "../../../components/ha-button";
10+
import "../../../components/buttons/ha-progress-button";
1011
import "../../../components/ha-checkbox";
1112
import "../../../components/ha-faded";
1213
import "../../../components/ha-markdown";
@@ -26,6 +27,8 @@ import {
2627
UpdateEntityFeature,
2728
updateIsInstalling,
2829
updateReleaseNotes,
30+
latestVersionIsSkipped,
31+
updateButtonIsDisabled,
2932
} from "../../../data/update";
3033
import type { HomeAssistant } from "../../../types";
3134
import { showAlertDialog } from "../../generic/show-dialog-box";
@@ -180,11 +183,6 @@ class MoreInfoUpdate extends LitElement {
180183
return nothing;
181184
}
182185

183-
const skippedVersion =
184-
this.stateObj.attributes.latest_version &&
185-
this.stateObj.attributes.skipped_version ===
186-
this.stateObj.attributes.latest_version;
187-
188186
const createBackupTexts = this._computeCreateBackupTexts();
189187

190188
return html`
@@ -312,7 +310,7 @@ class MoreInfoUpdate extends LitElement {
312310
<ha-button
313311
appearance="plain"
314312
@click=${this._handleSkip}
315-
.disabled=${skippedVersion ||
313+
.disabled=${latestVersionIsSkipped(this.stateObj) ||
316314
this.stateObj.state === BINARY_STATE_OFF ||
317315
updateIsInstalling(this.stateObj)}
318316
>
@@ -325,9 +323,8 @@ class MoreInfoUpdate extends LitElement {
325323
? html`
326324
<ha-button
327325
@click=${this._handleInstall}
328-
.disabled=${(this.stateObj.state === BINARY_STATE_OFF &&
329-
!skippedVersion) ||
330-
updateIsInstalling(this.stateObj)}
326+
.loading=${updateIsInstalling(this.stateObj)}
327+
.disabled=${updateButtonIsDisabled(this.stateObj)}
331328
>
332329
${this.hass.localize(
333330
"ui.dialogs.more_info_control.update.update"

0 commit comments

Comments
 (0)