Open assist from dashboard (#16829)

This commit is contained in:
Paul Bottein
2023-06-21 08:02:09 +02:00
committed by GitHub
parent 1cf24ffc8d
commit 1cb1bcf274
7 changed files with 128 additions and 14 deletions

View File

@@ -24,10 +24,10 @@ import { stopPropagation } from "../../common/dom/stop_propagation";
import "../../components/ha-button";
import "../../components/ha-button-menu";
import "../../components/ha-dialog";
import "../../components/ha-dialog-header";
import "../../components/ha-icon-button";
import "../../components/ha-list-item";
import "../../components/ha-textfield";
import "../../components/ha-dialog-header";
import type { HaTextField } from "../../components/ha-textfield";
import {
AssistPipeline,
@@ -41,6 +41,7 @@ import type { HomeAssistant } from "../../types";
import { AudioRecorder } from "../../util/audio-recorder";
import { documentationUrl } from "../../util/documentation-url";
import { showAlertDialog } from "../generic/show-dialog-box";
import { VoiceCommandDialogParams } from "./show-ha-voice-command-dialog";
interface Message {
who: string;
@@ -82,7 +83,13 @@ export class HaVoiceCommandDialog extends LitElement {
private _stt_binary_handler_id?: number | null;
public async showDialog(): Promise<void> {
private _pipelinePromise?: Promise<AssistPipeline>;
public async showDialog(params?: VoiceCommandDialogParams): Promise<void> {
if (params?.pipeline_id) {
this._pipelineId = params?.pipeline_id;
}
this._conversation = [
{
who: "hass",
@@ -92,6 +99,11 @@ export class HaVoiceCommandDialog extends LitElement {
this._opened = true;
await this.updateComplete;
this._scrollMessagesBottom();
await this._pipelinePromise;
if (params?.start_listening && this._pipeline?.stt_engine) {
this._toggleListening();
}
}
public async closeDialog(): Promise<void> {
@@ -230,7 +242,7 @@ export class HaVoiceCommandDialog extends LitElement {
<div class="listening-icon">
<ha-icon-button
.path=${mdiMicrophone}
@click=${this._toggleListening}
@click=${this._handleListeningButton}
.label=${this.hass.localize(
"ui.dialogs.voice_command.start_listening"
)}
@@ -275,7 +287,8 @@ export class HaVoiceCommandDialog extends LitElement {
private async _getPipeline() {
try {
this._pipeline = await getAssistPipeline(this.hass, this._pipelineId);
this._pipelinePromise = getAssistPipeline(this.hass, this._pipelineId);
this._pipeline = await this._pipelinePromise;
} catch (e: any) {
if (e.code === "not_found") {
this._pipelineId = undefined;
@@ -392,9 +405,13 @@ export class HaVoiceCommandDialog extends LitElement {
}
}
private _toggleListening(ev) {
private _handleListeningButton(ev) {
ev.stopPropagation();
ev.preventDefault();
this._toggleListening();
}
private _toggleListening() {
const supportsMicrophone = AudioRecorder.isSupported;
if (!supportsMicrophone) {
this._showNotSupportedMessage();