mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Add support for update entity's update_percentage state attribute (#22453)
* Add support for update entity's update_percentage state attribute * Update voice assistant wizard
This commit is contained in:
parent
e16e851952
commit
f1ab24da99
@ -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 {
|
||||
@ -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,
|
||||
@ -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>({
|
||||
@ -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");
|
||||
|
@ -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>`
|
||||
|
@ -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" />
|
||||
@ -69,7 +69,7 @@ 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>
|
||||
@ -77,7 +77,7 @@ export class HaVoiceAssistantSetupStepUpdate extends LitElement {
|
||||
${stateObj.state === "unavailable"
|
||||
? "Restarting voice assistant"
|
||||
: progressIsNumeric
|
||||
? `Installing ${stateObj.attributes.in_progress}%`
|
||||
? `Installing ${stateObj.attributes.update_percentage}%`
|
||||
: ""}
|
||||
</p>
|
||||
</div>`;
|
||||
|
Loading…
x
Reference in New Issue
Block a user