Inform user that subscription is needed for cloud services (#16318)

This commit is contained in:
Paul Bottein 2023-04-26 15:42:44 +02:00 committed by GitHub
parent a5759e36b2
commit addb66f21d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 6 deletions

View File

@ -22,6 +22,7 @@ import type { HomeAssistant } from "../../../types";
import { showVoiceAssistantPipelineDetailDialog } from "./show-dialog-voice-assistant-pipeline-detail";
import { brandsUrl } from "../../../util/brands-url";
import { formatLanguageCode } from "../../../common/language/format_language";
import { CloudStatusLoggedIn } from "../../../data/cloud";
export class AssistPref extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@ -30,6 +31,8 @@ export class AssistPref extends LitElement {
@state() private _preferred: string | null = null;
@property() public cloudStatus?: CloudStatusLoggedIn;
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
@ -125,6 +128,7 @@ export class AssistPref extends LitElement {
private async _openDialog(pipeline?: AssistPipeline): Promise<void> {
showVoiceAssistantPipelineDetailDialog(this, {
cloudActiveSubscription: this.cloudStatus?.active_subscription,
pipeline,
preferred: pipeline?.id === this._preferred,
createPipeline: async (values) => {

View File

@ -28,6 +28,8 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
@state() private _preferred?: boolean;
@state() private _cloudActive?: boolean;
@state() private _error?: Record<string, string>;
@state() private _submitting = false;
@ -40,13 +42,14 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
if (this._params.pipeline) {
this._data = this._params.pipeline;
this._preferred = this._params.preferred;
this._cloudActive = this._params.cloudActiveSubscription;
} else {
this._data = {
language: (
this.hass.config.language || this.hass.locale.language
).substring(0, 2),
stt_engine: "cloud",
tts_engine: "cloud",
stt_engine: this._cloudActive ? "cloud" : undefined,
tts_engine: this._cloudActive ? "cloud" : undefined,
};
}
}
@ -88,7 +91,7 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
>
<div class="content">
${this._error
? html`<ha-alert alert-type="error"> ${this._error} </ha-alert>`
? html`<ha-alert alert-type="error">${this._error}</ha-alert>`
: nothing}
<assist-pipeline-detail-config
.hass=${this.hass}
@ -104,6 +107,28 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
keys="conversation_engine,conversation_language"
@value-changed=${this._valueChanged}
></assist-pipeline-detail-conversation>
${!this._cloudActive &&
(this._data.tts_engine === "cloud" ||
this._data.stt_engine === "cloud")
? html`
<ha-alert alert-type="warning"
>${this.hass.localize(
"ui.panel.config.voice_assistants.assistants.pipeline.detail.no_cloud_message"
)}
<a
href="/config/cloud"
slot="action"
@click=${this.closeDialog}
>
<ha-button>
${this.hass.localize(
"ui.panel.config.voice_assistants.assistants.pipeline.detail.no_cloud_action"
)}
</ha-button>
</a>
</ha-alert>
`
: nothing}
<assist-pipeline-detail-stt
.hass=${this.hass}
.data=${this._data}
@ -236,7 +261,7 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
display: block;
}
ha-alert {
margin-bottom: 8px;
margin-bottom: 16px;
display: block;
}
a {

View File

@ -40,7 +40,10 @@ export class HaConfigVoiceAssistantsAssistants extends LitElement {
>
<div class="content">
${isComponentLoaded(this.hass, "assist_pipeline")
? html` <assist-pref .hass=${this.hass}></assist-pref> `
? html`<assist-pref
.hass=${this.hass}
.cloudStatus=${this.cloudStatus}
></assist-pref>`
: nothing}
${this.cloudStatus?.logged_in
? html`

View File

@ -5,6 +5,7 @@ import {
} from "../../../data/assist_pipeline";
export interface VoiceAssistantPipelineDetailsDialogParams {
cloudActiveSubscription?: boolean;
pipeline?: AssistPipeline;
preferred?: boolean;
createPipeline: (values: AssistPipelineMutableParams) => Promise<unknown>;

View File

@ -2068,7 +2068,9 @@
"title": "Text-to-speech",
"description": "When you are controlling your assistant with voice, the text-to-speech engine turns the conversation text responses into audio."
}
}
},
"no_cloud_message": "You should have an active cloud subscription to use cloud speech services.",
"no_cloud_action": "Subscribe"
}
},
"cloud": {