mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Take lang into account when search existing pipeline (#24866)
* Take lang into account when search existing pipeline * Simplify logic
This commit is contained in:
parent
8a2ab2eab4
commit
6e8bac2e58
@ -359,40 +359,24 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pipelines = await listAssistPipelines(this.hass);
|
const pipelines = await listAssistPipelines(this.hass);
|
||||||
const preferredPipeline = pipelines.pipelines.find(
|
|
||||||
(pipeline) => pipeline.id === pipelines.preferred_pipeline
|
if (pipelines.preferred_pipeline) {
|
||||||
);
|
pipelines.pipelines.sort((a) =>
|
||||||
|
a.id === pipelines.preferred_pipeline ? -1 : 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const ttsEntityIds = this._localTts.map((ent) => ent.entity_id);
|
const ttsEntityIds = this._localTts.map((ent) => ent.entity_id);
|
||||||
const sttEntityIds = this._localStt.map((ent) => ent.entity_id);
|
const sttEntityIds = this._localStt.map((ent) => ent.entity_id);
|
||||||
|
|
||||||
if (preferredPipeline) {
|
|
||||||
if (
|
|
||||||
preferredPipeline.conversation_engine ===
|
|
||||||
"conversation.home_assistant" &&
|
|
||||||
preferredPipeline.tts_engine &&
|
|
||||||
ttsEntityIds.includes(preferredPipeline.tts_engine) &&
|
|
||||||
preferredPipeline.stt_engine &&
|
|
||||||
sttEntityIds.includes(preferredPipeline.stt_engine)
|
|
||||||
) {
|
|
||||||
await this.hass.callService(
|
|
||||||
"select",
|
|
||||||
"select_option",
|
|
||||||
{ option: "preferred" },
|
|
||||||
{ entity_id: this.assistConfiguration?.pipeline_entity_id }
|
|
||||||
);
|
|
||||||
this._nextStep();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let localPipeline = pipelines.pipelines.find(
|
let localPipeline = pipelines.pipelines.find(
|
||||||
(pipeline) =>
|
(pipeline) =>
|
||||||
pipeline.conversation_engine === "conversation.home_assistant" &&
|
pipeline.conversation_engine === "conversation.home_assistant" &&
|
||||||
pipeline.tts_engine &&
|
pipeline.tts_engine &&
|
||||||
ttsEntityIds.includes(pipeline.tts_engine) &&
|
ttsEntityIds.includes(pipeline.tts_engine) &&
|
||||||
pipeline.stt_engine &&
|
pipeline.stt_engine &&
|
||||||
sttEntityIds.includes(pipeline.stt_engine)
|
sttEntityIds.includes(pipeline.stt_engine) &&
|
||||||
|
pipeline.language.split("-")[0] === this.language.split("-")[0]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!localPipeline) {
|
if (!localPipeline) {
|
||||||
|
@ -246,7 +246,7 @@ export class HaVoiceAssistantSetupStepPipeline extends LitElement {
|
|||||||
|
|
||||||
private async _fetchData() {
|
private async _fetchData() {
|
||||||
const cloud =
|
const cloud =
|
||||||
(await this._hasCloud()) && (await this._createCloudPipeline());
|
(await this._hasCloud()) && (await this._createCloudPipeline(false));
|
||||||
if (!cloud) {
|
if (!cloud) {
|
||||||
this._cloudChecked = true;
|
this._cloudChecked = true;
|
||||||
this._languageScores = (await getLanguageScores(this.hass)).languages;
|
this._languageScores = (await getLanguageScores(this.hass)).languages;
|
||||||
@ -264,7 +264,7 @@ export class HaVoiceAssistantSetupStepPipeline extends LitElement {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _createCloudPipeline(): Promise<boolean> {
|
private async _createCloudPipeline(useLanguage: boolean): Promise<boolean> {
|
||||||
let cloudTtsEntityId;
|
let cloudTtsEntityId;
|
||||||
let cloudSttEntityId;
|
let cloudSttEntityId;
|
||||||
for (const entity of Object.values(this.hass.entities)) {
|
for (const entity of Object.values(this.hass.entities)) {
|
||||||
@ -284,36 +284,20 @@ export class HaVoiceAssistantSetupStepPipeline extends LitElement {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const pipelines = await listAssistPipelines(this.hass);
|
const pipelines = await listAssistPipelines(this.hass);
|
||||||
const preferredPipeline = pipelines.pipelines.find(
|
|
||||||
(pipeline) => pipeline.id === pipelines.preferred_pipeline
|
|
||||||
);
|
|
||||||
|
|
||||||
if (preferredPipeline) {
|
if (pipelines.preferred_pipeline) {
|
||||||
if (
|
pipelines.pipelines.sort((a) =>
|
||||||
preferredPipeline.conversation_engine ===
|
a.id === pipelines.preferred_pipeline ? -1 : 0
|
||||||
"conversation.home_assistant" &&
|
);
|
||||||
preferredPipeline.tts_engine === cloudTtsEntityId &&
|
|
||||||
preferredPipeline.stt_engine === cloudSttEntityId
|
|
||||||
) {
|
|
||||||
await this.hass.callService(
|
|
||||||
"select",
|
|
||||||
"select_option",
|
|
||||||
{ option: "preferred" },
|
|
||||||
{ entity_id: this.assistConfiguration?.pipeline_entity_id }
|
|
||||||
);
|
|
||||||
fireEvent(this, "next-step", {
|
|
||||||
step: STEP.SUCCESS,
|
|
||||||
noPrevious: true,
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let cloudPipeline = pipelines.pipelines.find(
|
let cloudPipeline = pipelines.pipelines.find(
|
||||||
(pipeline) =>
|
(pipeline) =>
|
||||||
pipeline.conversation_engine === "conversation.home_assistant" &&
|
pipeline.conversation_engine === "conversation.home_assistant" &&
|
||||||
pipeline.tts_engine === cloudTtsEntityId &&
|
pipeline.tts_engine === cloudTtsEntityId &&
|
||||||
pipeline.stt_engine === cloudSttEntityId
|
pipeline.stt_engine === cloudSttEntityId &&
|
||||||
|
(!useLanguage ||
|
||||||
|
pipeline.language.split("-")[0] === this.language!.split("-")[0])
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!cloudPipeline) {
|
if (!cloudPipeline) {
|
||||||
@ -405,7 +389,7 @@ export class HaVoiceAssistantSetupStepPipeline extends LitElement {
|
|||||||
|
|
||||||
private async _setupCloud() {
|
private async _setupCloud() {
|
||||||
if (await this._hasCloud()) {
|
if (await this._hasCloud()) {
|
||||||
this._createCloudPipeline();
|
this._createCloudPipeline(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fireEvent(this, "next-step", { step: STEP.CLOUD });
|
fireEvent(this, "next-step", { step: STEP.CLOUD });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user