From 11ace6002a3b61a101dfe076d68d03a0ea496b9d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 26 Aug 2024 23:51:37 +0200 Subject: [PATCH] Fix Assist pipeline defaults (#21796) * Fix Assist pipeline defaults * Always set to NONE if nothing * Rewrite for readability --- .../ha-conversation-agent-picker.ts | 38 ++++++++++++++----- src/components/ha-stt-picker.ts | 34 +++++++++++++---- src/components/ha-tts-picker.ts | 34 +++++++++++++---- .../dialog-voice-assistant-pipeline-detail.ts | 38 +++++++++++++++---- 4 files changed, 113 insertions(+), 31 deletions(-) diff --git a/src/components/ha-conversation-agent-picker.ts b/src/components/ha-conversation-agent-picker.ts index 0b6416d4ac2e..cccd6e76f8f8 100644 --- a/src/components/ha-conversation-agent-picker.ts +++ b/src/components/ha-conversation-agent-picker.ts @@ -45,15 +45,35 @@ export class HaConversationAgentPicker extends LitElement { if (!this._agents) { return nothing; } - const value = - this.value ?? - (this.required && - (!this.language || - this._agents - .find((agent) => agent.id === "homeassistant") - ?.supported_languages.includes(this.language)) - ? "homeassistant" - : NONE); + let value = this.value; + if (!value && this.required) { + // Select Home Assistant conversation agent if it supports the language + for (const agent of this._agents) { + if ( + agent.id === "conversation.home_assistant" && + agent.supported_languages.includes(this.language!) + ) { + value = agent.id; + break; + } + } + if (!value) { + // Select the first agent that supports the language + for (const agent of this._agents) { + if ( + agent.supported_languages === "*" && + agent.supported_languages.includes(this.language!) + ) { + value = agent.id; + break; + } + } + } + } + if (!value) { + value = NONE; + } + return html` engine.supported_languages?.length !== 0 - ) - : NONE); + + let value = this.value; + if (!value && this.required) { + for (const entity of Object.values(this.hass.entities)) { + if ( + entity.platform === "cloud" && + computeDomain(entity.entity_id) === "stt" + ) { + value = entity.entity_id; + break; + } + } + + if (!value) { + for (const sttEngine of this._engines) { + if (sttEngine?.supported_languages?.length !== 0) { + value = sttEngine.engine_id; + break; + } + } + } + } + if (!value) { + value = NONE; + } + return html` engine.supported_languages?.length !== 0 - ) - : NONE); + + let value = this.value; + if (!value && this.required) { + for (const entity of Object.values(this.hass.entities)) { + if ( + entity.platform === "cloud" && + computeDomain(entity.entity_id) === "tts" + ) { + value = entity.entity_id; + break; + } + } + + if (!value) { + for (const ttsEngine of this._engines) { + if (ttsEngine?.supported_languages?.length !== 0) { + value = ttsEngine.engine_id; + break; + } + } + } + } + if (!value) { + value = NONE; + } + return html`