mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +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 {
|
interface UpdateEntityAttributes extends HassEntityAttributeBase {
|
||||||
auto_update: boolean | null;
|
auto_update: boolean | null;
|
||||||
installed_version: string | null;
|
installed_version: string | null;
|
||||||
in_progress: boolean | number;
|
in_progress: boolean;
|
||||||
latest_version: string | null;
|
latest_version: string | null;
|
||||||
release_summary: string | null;
|
release_summary: string | null;
|
||||||
release_url: string | null;
|
release_url: string | null;
|
||||||
skipped_version: string | null;
|
skipped_version: string | null;
|
||||||
title: string | null;
|
title: string | null;
|
||||||
|
update_percentage: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateEntity extends HassEntityBase {
|
export interface UpdateEntity extends HassEntityBase {
|
||||||
@ -38,7 +39,7 @@ export interface UpdateEntity extends HassEntityBase {
|
|||||||
|
|
||||||
export const updateUsesProgress = (entity: UpdateEntity): boolean =>
|
export const updateUsesProgress = (entity: UpdateEntity): boolean =>
|
||||||
supportsFeature(entity, UpdateEntityFeature.PROGRESS) &&
|
supportsFeature(entity, UpdateEntityFeature.PROGRESS) &&
|
||||||
typeof entity.attributes.in_progress === "number";
|
entity.attributes.update_percentage !== null;
|
||||||
|
|
||||||
export const updateCanInstall = (
|
export const updateCanInstall = (
|
||||||
entity: UpdateEntity,
|
entity: UpdateEntity,
|
||||||
@ -49,7 +50,7 @@ export const updateCanInstall = (
|
|||||||
supportsFeature(entity, UpdateEntityFeature.INSTALL);
|
supportsFeature(entity, UpdateEntityFeature.INSTALL);
|
||||||
|
|
||||||
export const updateIsInstalling = (entity: UpdateEntity): boolean =>
|
export const updateIsInstalling = (entity: UpdateEntity): boolean =>
|
||||||
updateUsesProgress(entity) || !!entity.attributes.in_progress;
|
!!entity.attributes.in_progress;
|
||||||
|
|
||||||
export const updateReleaseNotes = (hass: HomeAssistant, entityId: string) =>
|
export const updateReleaseNotes = (hass: HomeAssistant, entityId: string) =>
|
||||||
hass.callWS<string | null>({
|
hass.callWS<string | null>({
|
||||||
@ -183,10 +184,10 @@ export const computeUpdateStateDisplay = (
|
|||||||
if (updateIsInstalling(stateObj)) {
|
if (updateIsInstalling(stateObj)) {
|
||||||
const supportsProgress =
|
const supportsProgress =
|
||||||
supportsFeature(stateObj, UpdateEntityFeature.PROGRESS) &&
|
supportsFeature(stateObj, UpdateEntityFeature.PROGRESS) &&
|
||||||
typeof attributes.in_progress === "number";
|
attributes.update_percentage !== null;
|
||||||
if (supportsProgress) {
|
if (supportsProgress) {
|
||||||
return hass.localize("ui.card.update.installing_with_progress", {
|
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");
|
return hass.localize("ui.card.update.installing");
|
||||||
|
@ -47,9 +47,9 @@ class MoreInfoUpdate extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
${this.stateObj.attributes.in_progress
|
${this.stateObj.attributes.in_progress
|
||||||
? supportsFeature(this.stateObj, UpdateEntityFeature.PROGRESS) &&
|
? supportsFeature(this.stateObj, UpdateEntityFeature.PROGRESS) &&
|
||||||
typeof this.stateObj.attributes.in_progress === "number"
|
this.stateObj.attributes.update_percentage !== null
|
||||||
? html`<mwc-linear-progress
|
? html`<mwc-linear-progress
|
||||||
.progress=${this.stateObj.attributes.in_progress / 100}
|
.progress=${this.stateObj.attributes.update_percentage / 100}
|
||||||
buffer=""
|
buffer=""
|
||||||
></mwc-linear-progress>`
|
></mwc-linear-progress>`
|
||||||
: html`<mwc-linear-progress indeterminate></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 stateObj = this.hass.states[this.updateEntityId];
|
||||||
|
|
||||||
const progressIsNumeric =
|
const progressIsNumeric =
|
||||||
typeof stateObj?.attributes.in_progress === "number";
|
typeof stateObj?.attributes.update_percentage !== null;
|
||||||
|
|
||||||
return html`<div class="content">
|
return html`<div class="content">
|
||||||
<img src="/static/icons/casita/loading.png" />
|
<img src="/static/icons/casita/loading.png" />
|
||||||
@ -69,7 +69,7 @@ export class HaVoiceAssistantSetupStepUpdate extends LitElement {
|
|||||||
</p>
|
</p>
|
||||||
<ha-circular-progress
|
<ha-circular-progress
|
||||||
.value=${progressIsNumeric
|
.value=${progressIsNumeric
|
||||||
? stateObj.attributes.in_progress / 100
|
? stateObj.attributes.update_percentage / 100
|
||||||
: undefined}
|
: undefined}
|
||||||
.indeterminate=${!progressIsNumeric}
|
.indeterminate=${!progressIsNumeric}
|
||||||
></ha-circular-progress>
|
></ha-circular-progress>
|
||||||
@ -77,7 +77,7 @@ export class HaVoiceAssistantSetupStepUpdate extends LitElement {
|
|||||||
${stateObj.state === "unavailable"
|
${stateObj.state === "unavailable"
|
||||||
? "Restarting voice assistant"
|
? "Restarting voice assistant"
|
||||||
: progressIsNumeric
|
: progressIsNumeric
|
||||||
? `Installing ${stateObj.attributes.in_progress}%`
|
? `Installing ${stateObj.attributes.update_percentage}%`
|
||||||
: ""}
|
: ""}
|
||||||
</p>
|
</p>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user