From 19f54b6ba217047a3c97cf2310d1abd101739dcb Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 3 Dec 2024 12:01:54 +0100 Subject: [PATCH] Voice local: Small refactor and return when local already exists (#23113) --- .../voice-assistant-setup-step-local.ts | 40 +++++++++---------- .../voice-assistant-setup-step-pipeline.ts | 4 ++ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/dialogs/voice-assistant-setup/voice-assistant-setup-step-local.ts b/src/dialogs/voice-assistant-setup/voice-assistant-setup-step-local.ts index 69c50ef57192..cd00187d5a0e 100644 --- a/src/dialogs/voice-assistant-setup/voice-assistant-setup-step-local.ts +++ b/src/dialogs/voice-assistant-setup/voice-assistant-setup-step-local.ts @@ -24,6 +24,7 @@ import type { HomeAssistant } from "../../types"; import { documentationUrl } from "../../util/documentation-url"; import { AssistantSetupStyles } from "./styles"; import { STEP } from "./voice-assistant-setup-dialog"; +import { nextRender } from "../../common/util/render-status"; @customElement("ha-voice-assistant-setup-step-local") export class HaVoiceAssistantSetupStepLocal extends LitElement { @@ -138,6 +139,7 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement { } if (this._localTts.length && this._localStt.length) { this._pickOrCreatePipelineExists(); + return; } if (!isComponentLoaded(this.hass, "hassio")) { this._state = "NOT_SUPPORTED"; @@ -148,38 +150,30 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement { const { addons } = await fetchHassioAddonsInfo(this.hass); const whisper = addons.find((addon) => addon.slug === "core_whisper"); const piper = addons.find((addon) => addon.slug === "core_piper"); - if (piper && !this._localTts.length) { - if (piper.state !== "started") { + if (!this._localTts.length) { + if (!piper) { + this._detailState = "Installing Piper add-on"; + await installHassioAddon(this.hass, "core_piper"); + } + if (!piper || piper.state !== "started") { this._detailState = "Starting Piper add-on"; await startHassioAddon(this.hass, "core_piper"); } this._detailState = "Setting up Piper"; await this._setupConfigEntry("piper"); } - if (whisper && !this._localStt.length) { - if (whisper.state !== "started") { + if (!this._localStt.length) { + if (!whisper) { + this._detailState = "Installing Whisper add-on"; + await installHassioAddon(this.hass, "core_whisper"); + } + if (!whisper || whisper.state !== "started") { this._detailState = "Starting Whisper add-on"; await startHassioAddon(this.hass, "core_whisper"); } this._detailState = "Setting up Whisper"; await this._setupConfigEntry("whisper"); } - if (!piper) { - this._detailState = "Installing Piper add-on"; - await installHassioAddon(this.hass, "core_piper"); - this._detailState = "Starting Piper add-on"; - await startHassioAddon(this.hass, "core_piper"); - this._detailState = "Setting up Piper"; - await this._setupConfigEntry("piper"); - } - if (!whisper) { - this._detailState = "Installing Whisper add-on"; - await installHassioAddon(this.hass, "core_whisper"); - this._detailState = "Starting Whisper add-on"; - await startHassioAddon(this.hass, "core_whisper"); - this._detailState = "Setting up Whisper"; - await this._setupConfigEntry("whisper"); - } this._detailState = "Creating assistant"; await this._findEntitiesAndCreatePipeline(); } catch (e: any) { @@ -259,6 +253,9 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement { this._localTts[0].entity_id, this._localStt[0].entity_id ); + + // wait a render so the `hui-select-entity-row` is also updated and doesn't undo the select action + await nextRender(); } await this.hass.callService( @@ -340,6 +337,9 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement { this._localStt[0].entity_id ); + // wait a render so the `hui-select-entity-row` is also updated and doesn't undo the select action + await nextRender(); + await this.hass.callService( "select", "select_option", diff --git a/src/dialogs/voice-assistant-setup/voice-assistant-setup-step-pipeline.ts b/src/dialogs/voice-assistant-setup/voice-assistant-setup-step-pipeline.ts index d008d312f045..781802d3481e 100644 --- a/src/dialogs/voice-assistant-setup/voice-assistant-setup-step-pipeline.ts +++ b/src/dialogs/voice-assistant-setup/voice-assistant-setup-step-pipeline.ts @@ -17,6 +17,7 @@ import type { HomeAssistant } from "../../types"; import { AssistantSetupStyles } from "./styles"; import { STEP } from "./voice-assistant-setup-dialog"; import { documentationUrl } from "../../util/documentation-url"; +import { nextRender } from "../../common/util/render-status"; @customElement("ha-voice-assistant-setup-step-pipeline") export class HaVoiceAssistantSetupStepPipeline extends LitElement { @@ -240,6 +241,9 @@ export class HaVoiceAssistantSetupStepPipeline extends LitElement { wake_word_entity: null, wake_word_id: null, }); + + // wait a render so the `hui-select-entity-row` is also updated and doesn't undo the select action + await nextRender(); } await this.hass.callService(