Update update entity in voice flow (#22178)

This commit is contained in:
Bram Kragten 2024-10-01 18:34:18 +02:00 committed by GitHub
parent f7d5c5f850
commit 57cf2c1341
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,7 +2,7 @@ import { css, html, LitElement, nothing, PropertyValues } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import "../../components/ha-circular-progress"; import "../../components/ha-circular-progress";
import { UNAVAILABLE } from "../../data/entity"; import { OFF, ON, UNAVAILABLE } from "../../data/entity";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import { AssistantSetupStyles } from "./styles"; import { AssistantSetupStyles } from "./styles";
@ -14,6 +14,8 @@ export class HaVoiceAssistantSetupStepUpdate extends LitElement {
private _updated = false; private _updated = false;
private _refreshTimeout?: number;
protected override willUpdate(changedProperties: PropertyValues): void { protected override willUpdate(changedProperties: PropertyValues): void {
super.willUpdate(changedProperties); super.willUpdate(changedProperties);
@ -28,17 +30,18 @@ export class HaVoiceAssistantSetupStepUpdate extends LitElement {
const oldState = oldHass.states[this.updateEntityId]; const oldState = oldHass.states[this.updateEntityId];
const newState = this.hass.states[this.updateEntityId]; const newState = this.hass.states[this.updateEntityId];
if ( if (
oldState?.state === UNAVAILABLE && (oldState?.state === UNAVAILABLE &&
newState?.state !== UNAVAILABLE newState?.state !== UNAVAILABLE) ||
(oldState?.state === OFF && newState?.state === ON)
) { ) {
// Device is rebooted, let's move on // Device is rebooted, let's move on
this._tryUpdate(); this._tryUpdate(false);
} }
} }
} }
if (changedProperties.has("updateEntityId")) { if (changedProperties.has("updateEntityId")) {
this._tryUpdate(); this._tryUpdate(true);
} }
} }
@ -54,7 +57,11 @@ export class HaVoiceAssistantSetupStepUpdate extends LitElement {
return html`<div class="content"> return html`<div class="content">
<img src="/static/icons/casita/loading.png" /> <img src="/static/icons/casita/loading.png" />
<h1>Updating your voice assistant</h1> <h1>
${stateObj.state === OFF
? "Checking for updates"
: "Updating your voice assistant"}
</h1>
<p class="secondary"> <p class="secondary">
We are making sure you have the latest and greatest version of your We are making sure you have the latest and greatest version of your
voice assistant. This may take a few minutes. voice assistant. This may take a few minutes.
@ -75,7 +82,8 @@ export class HaVoiceAssistantSetupStepUpdate extends LitElement {
</div>`; </div>`;
} }
private async _tryUpdate() { private async _tryUpdate(refreshUpdate: boolean) {
clearTimeout(this._refreshTimeout);
if (!this.updateEntityId) { if (!this.updateEntityId) {
return; return;
} }
@ -91,6 +99,16 @@ export class HaVoiceAssistantSetupStepUpdate extends LitElement {
{}, {},
{ entity_id: updateEntity.entity_id } { entity_id: updateEntity.entity_id }
); );
} else if (refreshUpdate) {
await this.hass.callService(
"homeassistant",
"update_entity",
{},
{ entity_id: this.updateEntityId }
);
this._refreshTimeout = window.setTimeout(() => {
this._nextStep();
}, 5000);
} else { } else {
this._nextStep(); this._nextStep();
} }