Skip to content

Commit

Permalink
Add support for update entity's update_percentage state attribute (#2…
Browse files Browse the repository at this point in the history
…2453)

* Add support for update entity's update_percentage state attribute

* Update voice assistant wizard
  • Loading branch information
emontnemery authored Oct 23, 2024
1 parent e16e851 commit f1ab24d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/data/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ export enum UpdateEntityFeature {
interface UpdateEntityAttributes extends HassEntityAttributeBase {
auto_update: boolean | null;
installed_version: string | null;
in_progress: boolean | number;
in_progress: boolean;
latest_version: string | null;
release_summary: string | null;
release_url: string | null;
skipped_version: string | null;
title: string | null;
update_percentage: number | null;
}

export interface UpdateEntity extends HassEntityBase {
Expand All @@ -38,7 +39,7 @@ export interface UpdateEntity extends HassEntityBase {

export const updateUsesProgress = (entity: UpdateEntity): boolean =>
supportsFeature(entity, UpdateEntityFeature.PROGRESS) &&
typeof entity.attributes.in_progress === "number";
entity.attributes.update_percentage !== null;

export const updateCanInstall = (
entity: UpdateEntity,
Expand All @@ -49,7 +50,7 @@ export const updateCanInstall = (
supportsFeature(entity, UpdateEntityFeature.INSTALL);

export const updateIsInstalling = (entity: UpdateEntity): boolean =>
updateUsesProgress(entity) || !!entity.attributes.in_progress;
!!entity.attributes.in_progress;

export const updateReleaseNotes = (hass: HomeAssistant, entityId: string) =>
hass.callWS<string | null>({
Expand Down Expand Up @@ -183,10 +184,10 @@ export const computeUpdateStateDisplay = (
if (updateIsInstalling(stateObj)) {
const supportsProgress =
supportsFeature(stateObj, UpdateEntityFeature.PROGRESS) &&
typeof attributes.in_progress === "number";
attributes.update_percentage !== null;
if (supportsProgress) {
return hass.localize("ui.card.update.installing_with_progress", {
progress: attributes.in_progress as number,
progress: attributes.update_percentage,
});
}
return hass.localize("ui.card.update.installing");
Expand Down
4 changes: 2 additions & 2 deletions src/dialogs/more-info/controls/more-info-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class MoreInfoUpdate extends LitElement {
return html`
${this.stateObj.attributes.in_progress
? supportsFeature(this.stateObj, UpdateEntityFeature.PROGRESS) &&
typeof this.stateObj.attributes.in_progress === "number"
this.stateObj.attributes.update_percentage !== null
? html`<mwc-linear-progress
.progress=${this.stateObj.attributes.in_progress / 100}
.progress=${this.stateObj.attributes.update_percentage / 100}
buffer=""
></mwc-linear-progress>`
: html`<mwc-linear-progress indeterminate></mwc-linear-progress>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class HaVoiceAssistantSetupStepUpdate extends LitElement {
const stateObj = this.hass.states[this.updateEntityId];

const progressIsNumeric =
typeof stateObj?.attributes.in_progress === "number";
typeof stateObj?.attributes.update_percentage !== null;

return html`<div class="content">
<img src="/static/icons/casita/loading.png" />
Expand All @@ -69,15 +69,15 @@ export class HaVoiceAssistantSetupStepUpdate extends LitElement {
</p>
<ha-circular-progress
.value=${progressIsNumeric
? stateObj.attributes.in_progress / 100
? stateObj.attributes.update_percentage / 100
: undefined}
.indeterminate=${!progressIsNumeric}
></ha-circular-progress>
<p>
${stateObj.state === "unavailable"
? "Restarting voice assistant"
: progressIsNumeric
? `Installing ${stateObj.attributes.in_progress}%`
? `Installing ${stateObj.attributes.update_percentage}%`
: ""}
</p>
</div>`;
Expand Down

0 comments on commit f1ab24d

Please sign in to comment.