Ask to use cloud pipeline as preferred (#16286)

* Ask to use cloud pipeline as preferred

* Update
This commit is contained in:
Bram Kragten 2023-04-26 06:36:51 +02:00 committed by GitHub
parent e0c4b85ef1
commit 10d476195d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 7 deletions

View File

@ -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");

View File

@ -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") {

View File

@ -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",