Voice local: Small refactor and return when local already exists (#23113)

This commit is contained in:
Bram Kragten 2024-12-03 12:01:54 +01:00
parent 4f76e66cc0
commit 8beb93b695
2 changed files with 24 additions and 20 deletions

View File

@ -24,6 +24,7 @@ import type { HomeAssistant } from "../../types";
import { documentationUrl } from "../../util/documentation-url"; import { documentationUrl } from "../../util/documentation-url";
import { AssistantSetupStyles } from "./styles"; import { AssistantSetupStyles } from "./styles";
import { STEP } from "./voice-assistant-setup-dialog"; import { STEP } from "./voice-assistant-setup-dialog";
import { nextRender } from "../../common/util/render-status";
@customElement("ha-voice-assistant-setup-step-local") @customElement("ha-voice-assistant-setup-step-local")
export class HaVoiceAssistantSetupStepLocal extends LitElement { export class HaVoiceAssistantSetupStepLocal extends LitElement {
@ -138,6 +139,7 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement {
} }
if (this._localTts.length && this._localStt.length) { if (this._localTts.length && this._localStt.length) {
this._pickOrCreatePipelineExists(); this._pickOrCreatePipelineExists();
return;
} }
if (!isComponentLoaded(this.hass, "hassio")) { if (!isComponentLoaded(this.hass, "hassio")) {
this._state = "NOT_SUPPORTED"; this._state = "NOT_SUPPORTED";
@ -148,38 +150,30 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement {
const { addons } = await fetchHassioAddonsInfo(this.hass); const { addons } = await fetchHassioAddonsInfo(this.hass);
const whisper = addons.find((addon) => addon.slug === "core_whisper"); const whisper = addons.find((addon) => addon.slug === "core_whisper");
const piper = addons.find((addon) => addon.slug === "core_piper"); const piper = addons.find((addon) => addon.slug === "core_piper");
if (piper && !this._localTts.length) { if (!this._localTts.length) {
if (piper.state !== "started") { 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"; this._detailState = "Starting Piper add-on";
await startHassioAddon(this.hass, "core_piper"); await startHassioAddon(this.hass, "core_piper");
} }
this._detailState = "Setting up Piper"; this._detailState = "Setting up Piper";
await this._setupConfigEntry("piper"); await this._setupConfigEntry("piper");
} }
if (whisper && !this._localStt.length) { if (!this._localStt.length) {
if (whisper.state !== "started") { 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"; this._detailState = "Starting Whisper add-on";
await startHassioAddon(this.hass, "core_whisper"); await startHassioAddon(this.hass, "core_whisper");
} }
this._detailState = "Setting up Whisper"; this._detailState = "Setting up Whisper";
await this._setupConfigEntry("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"; this._detailState = "Creating assistant";
await this._findEntitiesAndCreatePipeline(); await this._findEntitiesAndCreatePipeline();
} catch (e: any) { } catch (e: any) {
@ -259,6 +253,9 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement {
this._localTts[0].entity_id, this._localTts[0].entity_id,
this._localStt[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( await this.hass.callService(
@ -340,6 +337,9 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement {
this._localStt[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( await this.hass.callService(
"select", "select",
"select_option", "select_option",

View File

@ -17,6 +17,7 @@ import type { HomeAssistant } from "../../types";
import { AssistantSetupStyles } from "./styles"; import { AssistantSetupStyles } from "./styles";
import { STEP } from "./voice-assistant-setup-dialog"; import { STEP } from "./voice-assistant-setup-dialog";
import { documentationUrl } from "../../util/documentation-url"; import { documentationUrl } from "../../util/documentation-url";
import { nextRender } from "../../common/util/render-status";
@customElement("ha-voice-assistant-setup-step-pipeline") @customElement("ha-voice-assistant-setup-step-pipeline")
export class HaVoiceAssistantSetupStepPipeline extends LitElement { export class HaVoiceAssistantSetupStepPipeline extends LitElement {
@ -240,6 +241,9 @@ export class HaVoiceAssistantSetupStepPipeline extends LitElement {
wake_word_entity: null, wake_word_entity: null,
wake_word_id: 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( await this.hass.callService(