From e765cc10fb0517ff2cc1b66a08f14f4fec5b755a Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Fri, 28 Mar 2025 13:53:08 +0100 Subject: [PATCH] Fix voice flow (#24825) * Fix voice flow * Apply suggestions from code review --------- Co-authored-by: Paulus Schoutsen --- .../voice-assistant-setup-step-local.ts | 18 +++++++------ .../voice-assistant-setup-step-pipeline.ts | 25 +++++++++++-------- src/translations/en.json | 4 +-- 3 files changed, 26 insertions(+), 21 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 69c1381233..d0765f589b 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 @@ -325,14 +325,16 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement { (flow) => flow.handler === "wyoming" && flow.context.source === "hassio" && - (flow.context.configuration_url.includes( - type === "tts" ? this._ttsHostName : this._sttHostName - ) || - flow.context.title_placeholders.title - .toLowerCase() - .includes( - type === "tts" ? this._ttsProviderName : this._sttProviderName - )) + ((flow.context.configuration_url && + flow.context.configuration_url.includes( + type === "tts" ? this._ttsAddonName : this._sttAddonName + )) || + (flow.context.title_placeholders.title && + flow.context.title_placeholders.title + .toLowerCase() + .includes( + type === "tts" ? this._ttsProviderName : this._sttProviderName + ))) ); } 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 d1fb161d30..f3bda9c260 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 @@ -15,7 +15,7 @@ import { } from "../../data/assist_pipeline"; import type { AssistSatelliteConfiguration } from "../../data/assist_satellite"; import { fetchCloudStatus } from "../../data/cloud"; -import type { LanguageScores } from "../../data/conversation"; +import type { LanguageScore, LanguageScores } from "../../data/conversation"; import { getLanguageScores, listAgents } from "../../data/conversation"; import { listSTTEngines } from "../../data/stt"; import { listTTSEngines, listTTSVoices } from "../../data/tts"; @@ -26,6 +26,12 @@ import { documentationUrl } from "../../util/documentation-url"; const OPTIONS = ["cloud", "focused_local", "full_local"] as const; +const EMPTY_SCORE: LanguageScore = { + cloud: 0, + focused_local: 0, + full_local: 0, +}; + @customElement("ha-voice-assistant-setup-step-pipeline") export class HaVoiceAssistantSetupStepPipeline extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -61,12 +67,12 @@ export class HaVoiceAssistantSetupStepPipeline extends LitElement { this._languageScores ) { const lang = this.language; - if (this._value && this._languageScores[lang][this._value] === 0) { + if (this._value && this._languageScores[lang]?.[this._value] === 0) { this._value = undefined; } if (!this._value) { this._value = this._getOptions( - this._languageScores[lang], + this._languageScores[lang] || EMPTY_SCORE, this.hass.localize ).supportedOptions[0]?.value as | "cloud" @@ -147,12 +153,9 @@ export class HaVoiceAssistantSetupStepPipeline extends LitElement { `; } - const score = this._languageScores[this.language]; + const score = this._languageScores[this.language] || EMPTY_SCORE; - const options = this._getOptions( - score || { cloud: 3, focused_local: 0, full_local: 0 }, - this.hass.localize - ); + const options = this._getOptions(score, this.hass.localize); const performance = !this._value ? "" @@ -162,11 +165,11 @@ export class HaVoiceAssistantSetupStepPipeline extends LitElement { const commands = !this._value ? "" - : score?.[this._value] > 2 + : score[this._value] > 2 ? "high" - : score?.[this._value] > 1 + : score[this._value] > 1 ? "ready" - : score?.[this._value] > 0 + : score[this._value] > 0 ? "low" : ""; diff --git a/src/translations/en.json b/src/translations/en.json index a030e84897..bfaffcf359 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3431,9 +3431,9 @@ }, "local": { "title": "Installing add-ons", - "secondary": "The Whisper and Piper add-ons are being installed and configured based on your hardware.", + "secondary": "The add-ons for speech-to-text and text-to-speech are being installed and configured based on your hardware.", "failed_title": "Failed to install add-ons", - "failed_secondary": "We were unable to install the Whisper and Piper add-ons automatically for you. Read the documentation to learn how to install them.", + "failed_secondary": "We were unable to install the add-ons for speech-to-text and text-to-speech automatically for you. Read the documentation to learn how to install them.", "not_supported_title": "Installation of add-ons is not supported on your system", "not_supported_secondary": "Your system is not supported to automatically install a local TTS and STT provider. Learn how to set up local TTS and STT providers in the documentation.", "local_pipeline": "Local Assistant",