From 10d476195da4e6e21f833a6cfc83181555855662 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 26 Apr 2023 06:36:51 +0200 Subject: [PATCH] Ask to use cloud pipeline as preferred (#16286) * Ask to use cloud pipeline as preferred * Update --- src/data/cloud.ts | 12 +++++++---- src/panels/config/cloud/login/cloud-login.ts | 22 ++++++++++++++++++-- src/translations/en.json | 4 +++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/data/cloud.ts b/src/data/cloud.ts index 454bbcc482..694d468790 100644 --- a/src/data/cloud.ts +++ b/src/data/cloud.ts @@ -76,10 +76,14 @@ export const cloudLogin = ( email: string, password: string ) => - hass.callApi("POST", "cloud/login", { - email, - password, - }); + hass.callApi<{ success: boolean; cloud_pipeline?: string }>( + "POST", + "cloud/login", + { + email, + password, + } + ); export const cloudLogout = (hass: HomeAssistant) => hass.callApi("POST", "cloud/logout"); diff --git a/src/panels/config/cloud/login/cloud-login.ts b/src/panels/config/cloud/login/cloud-login.ts index 36dcf84d39..cb26af168f 100644 --- a/src/panels/config/cloud/login/cloud-login.ts +++ b/src/panels/config/cloud/login/cloud-login.ts @@ -12,12 +12,16 @@ import "../../../../components/ha-icon-next"; import type { HaTextField } from "../../../../components/ha-textfield"; import "../../../../components/ha-textfield"; import { cloudLogin } from "../../../../data/cloud"; -import { showAlertDialog } from "../../../../dialogs/generic/show-dialog-box"; +import { + showAlertDialog, + showConfirmationDialog, +} from "../../../../dialogs/generic/show-dialog-box"; import "../../../../layouts/hass-subpage"; import { haStyle } from "../../../../resources/styles"; import "../../../../styles/polymer-ha-style"; import { HomeAssistant } from "../../../../types"; import "../../ha-config-section"; +import { setAssistPipelinePreferred } from "../../../../data/assist_pipeline"; @customElement("cloud-login") export class CloudLogin extends LitElement { @@ -210,10 +214,24 @@ export class CloudLogin extends LitElement { this._requestInProgress = true; try { - await cloudLogin(this.hass, email, password); + const result = await cloudLogin(this.hass, email, password); fireEvent(this, "ha-refresh-cloud-status"); this.email = ""; this._password = ""; + if (result.cloud_pipeline) { + if ( + await showConfirmationDialog(this, { + title: this.hass.localize( + "ui.panel.config.cloud.login.cloud_pipeline_title" + ), + text: this.hass.localize( + "ui.panel.config.cloud.login.cloud_pipeline_text" + ), + }) + ) { + setAssistPipelinePreferred(this.hass, result.cloud_pipeline); + } + } } catch (err: any) { const errCode = err && err.body && err.body.code; if (errCode === "PasswordChangeRequired") { diff --git a/src/translations/en.json b/src/translations/en.json index 4ef7ad195f..91964f2968 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2755,7 +2755,9 @@ "start_trial": "Start your free 1 month trial", "trial_info": "No payment information necessary", "alert_password_change_required": "You need to change your password before logging in.", - "alert_email_confirm_necessary": "You need to confirm your email before logging in." + "alert_email_confirm_necessary": "You need to confirm your email before logging in.", + "cloud_pipeline_title": "Want to use Home Assistant Cloud for your voice assistant?", + "cloud_pipeline_text": "We created a new assistant for you, using the great text-to-speech and speech-to-text engines from Home Assistant Cloud. Would you like to set this assistant as the preferred assistant?" }, "forgot_password": { "title": "Forgot password",