mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Add last_used option for pipeline and explicit default (#17329)
* Add last-used option for pipeline and explicit default * Default to last used
This commit is contained in:
parent
4c9066a4b0
commit
4946c00d34
@ -16,7 +16,8 @@ import "./ha-list-item";
|
|||||||
import "./ha-select";
|
import "./ha-select";
|
||||||
import type { HaSelect } from "./ha-select";
|
import type { HaSelect } from "./ha-select";
|
||||||
|
|
||||||
const PREFERRED = "__PREFERRED_PIPELINE_OPTION__";
|
const PREFERRED = "preferred";
|
||||||
|
const LAST_USED = "last_used";
|
||||||
|
|
||||||
@customElement("ha-assist-pipeline-picker")
|
@customElement("ha-assist-pipeline-picker")
|
||||||
export class HaAssistPipelinePicker extends LitElement {
|
export class HaAssistPipelinePicker extends LitElement {
|
||||||
@ -30,15 +31,21 @@ export class HaAssistPipelinePicker extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public required = false;
|
@property({ type: Boolean }) public required = false;
|
||||||
|
|
||||||
|
@property() public includeLastUsed = false;
|
||||||
|
|
||||||
@state() _pipelines?: AssistPipeline[];
|
@state() _pipelines?: AssistPipeline[];
|
||||||
|
|
||||||
@state() _preferredPipeline: string | null = null;
|
@state() _preferredPipeline: string | null = null;
|
||||||
|
|
||||||
|
private get _default() {
|
||||||
|
return this.includeLastUsed ? LAST_USED : PREFERRED;
|
||||||
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this._pipelines) {
|
if (!this._pipelines) {
|
||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
const value = this.value ?? PREFERRED;
|
const value = this.value ?? this._default;
|
||||||
return html`
|
return html`
|
||||||
<ha-select
|
<ha-select
|
||||||
.label=${this.label ||
|
.label=${this.label ||
|
||||||
@ -51,6 +58,15 @@ export class HaAssistPipelinePicker extends LitElement {
|
|||||||
fixedMenuPosition
|
fixedMenuPosition
|
||||||
naturalMenuWidth
|
naturalMenuWidth
|
||||||
>
|
>
|
||||||
|
${this.includeLastUsed
|
||||||
|
? html`
|
||||||
|
<ha-list-item .value=${LAST_USED}>
|
||||||
|
${this.hass!.localize(
|
||||||
|
"ui.components.pipeline-picker.last_used"
|
||||||
|
)}
|
||||||
|
</ha-list-item>
|
||||||
|
`
|
||||||
|
: null}
|
||||||
<ha-list-item .value=${PREFERRED}>
|
<ha-list-item .value=${PREFERRED}>
|
||||||
${this.hass!.localize("ui.components.pipeline-picker.preferred", {
|
${this.hass!.localize("ui.components.pipeline-picker.preferred", {
|
||||||
preferred: this._pipelines.find(
|
preferred: this._pipelines.find(
|
||||||
@ -93,11 +109,11 @@ export class HaAssistPipelinePicker extends LitElement {
|
|||||||
!this.hass ||
|
!this.hass ||
|
||||||
target.value === "" ||
|
target.value === "" ||
|
||||||
target.value === this.value ||
|
target.value === this.value ||
|
||||||
(this.value === undefined && target.value === PREFERRED)
|
(this.value === undefined && target.value === this._default)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.value = target.value === PREFERRED ? undefined : target.value;
|
this.value = target.value === this._default ? undefined : target.value;
|
||||||
fireEvent(this, "value-changed", { value: this.value });
|
fireEvent(this, "value-changed", { value: this.value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,19 @@ export class HaAssistPipelineSelector extends LitElement {
|
|||||||
@property({ type: Boolean }) public required = true;
|
@property({ type: Boolean }) public required = true;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`<ha-assist-pipeline-picker
|
return html`
|
||||||
.hass=${this.hass}
|
<ha-assist-pipeline-picker
|
||||||
.value=${this.value}
|
.hass=${this.hass}
|
||||||
.label=${this.label}
|
.value=${this.value}
|
||||||
.helper=${this.helper}
|
.label=${this.label}
|
||||||
.disabled=${this.disabled}
|
.helper=${this.helper}
|
||||||
.required=${this.required}
|
.disabled=${this.disabled}
|
||||||
></ha-assist-pipeline-picker>`;
|
.required=${this.required}
|
||||||
|
.includeLastUsed=${Boolean(
|
||||||
|
this.selector.assist_pipeline?.include_last_used
|
||||||
|
)}
|
||||||
|
></ha-assist-pipeline-picker>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
static styles = css`
|
static styles = css`
|
||||||
|
@ -278,7 +278,9 @@ export interface ObjectSelector {
|
|||||||
|
|
||||||
export interface AssistPipelineSelector {
|
export interface AssistPipelineSelector {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
assist_pipeline: {} | null;
|
assist_pipeline: {
|
||||||
|
include_last_used?: boolean;
|
||||||
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SelectOption {
|
export interface SelectOption {
|
||||||
|
@ -87,9 +87,16 @@ export class HaVoiceCommandDialog extends LitElement {
|
|||||||
|
|
||||||
private _pipelinePromise?: Promise<AssistPipeline>;
|
private _pipelinePromise?: Promise<AssistPipeline>;
|
||||||
|
|
||||||
public async showDialog(params?: VoiceCommandDialogParams): Promise<void> {
|
public async showDialog(
|
||||||
if (params?.pipeline_id) {
|
params: Required<VoiceCommandDialogParams>
|
||||||
this._pipelineId = params?.pipeline_id;
|
): Promise<void> {
|
||||||
|
if (params.pipeline_id === "last_used") {
|
||||||
|
// Do not set pipeline id (retrieve from storage)
|
||||||
|
} else if (params.pipeline_id === "preferred") {
|
||||||
|
await this._loadPipelines();
|
||||||
|
this._pipelineId = this._preferredPipeline;
|
||||||
|
} else {
|
||||||
|
this._pipelineId = params.pipeline_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._conversation = [
|
this._conversation = [
|
||||||
@ -103,7 +110,11 @@ export class HaVoiceCommandDialog extends LitElement {
|
|||||||
this._scrollMessagesBottom();
|
this._scrollMessagesBottom();
|
||||||
|
|
||||||
await this._pipelinePromise;
|
await this._pipelinePromise;
|
||||||
if (params?.start_listening && this._pipeline?.stt_engine) {
|
if (
|
||||||
|
params?.start_listening &&
|
||||||
|
this._pipeline?.stt_engine &&
|
||||||
|
AudioRecorder.isSupported
|
||||||
|
) {
|
||||||
this._toggleListening();
|
this._toggleListening();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,21 +4,22 @@ import { HomeAssistant } from "../../types";
|
|||||||
const loadVoiceCommandDialog = () => import("./ha-voice-command-dialog");
|
const loadVoiceCommandDialog = () => import("./ha-voice-command-dialog");
|
||||||
|
|
||||||
export interface VoiceCommandDialogParams {
|
export interface VoiceCommandDialogParams {
|
||||||
pipeline_id?: string;
|
pipeline_id: "last_used" | "preferred" | string;
|
||||||
start_listening?: boolean;
|
start_listening?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const showVoiceCommandDialog = (
|
export const showVoiceCommandDialog = (
|
||||||
element: HTMLElement,
|
element: HTMLElement,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
dialogParams?: VoiceCommandDialogParams
|
dialogParams: VoiceCommandDialogParams
|
||||||
): void => {
|
): void => {
|
||||||
if (hass.auth.external?.config.hasAssist) {
|
if (hass.auth.external?.config.hasAssist) {
|
||||||
hass.auth.external!.fireMessage({
|
hass.auth.external!.fireMessage({
|
||||||
type: "assist/show",
|
type: "assist/show",
|
||||||
payload: {
|
payload: {
|
||||||
pipeline_id: dialogParams?.pipeline_id,
|
pipeline_id: dialogParams.pipeline_id,
|
||||||
start_listening: dialogParams?.start_listening,
|
// Start listening by default for app
|
||||||
|
start_listening: dialogParams.start_listening ?? true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -26,6 +27,10 @@ export const showVoiceCommandDialog = (
|
|||||||
fireEvent(element, "show-dialog", {
|
fireEvent(element, "show-dialog", {
|
||||||
dialogTag: "ha-voice-command-dialog",
|
dialogTag: "ha-voice-command-dialog",
|
||||||
dialogImport: loadVoiceCommandDialog,
|
dialogImport: loadVoiceCommandDialog,
|
||||||
dialogParams,
|
dialogParams: {
|
||||||
|
pipeline_id: dialogParams.pipeline_id,
|
||||||
|
// Don't start listening by default for web
|
||||||
|
start_listening: dialogParams.start_listening ?? false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -98,8 +98,8 @@ interface EMOutgoingMessageSidebarShow extends EMMessage {
|
|||||||
interface EMOutgoingMessageAssistShow extends EMMessage {
|
interface EMOutgoingMessageAssistShow extends EMMessage {
|
||||||
type: "assist/show";
|
type: "assist/show";
|
||||||
payload?: {
|
payload?: {
|
||||||
pipeline_id?: string;
|
pipeline_id: "preferred" | "last_used" | string;
|
||||||
start_listening?: boolean;
|
start_listening: boolean;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +164,8 @@ export const handleAction = async (
|
|||||||
}
|
}
|
||||||
case "assist": {
|
case "assist": {
|
||||||
showVoiceCommandDialog(node, hass, {
|
showVoiceCommandDialog(node, hass, {
|
||||||
start_listening: actionConfig.start_listening,
|
start_listening: actionConfig.start_listening ?? false,
|
||||||
pipeline_id: actionConfig.pipeline_id,
|
pipeline_id: actionConfig.pipeline_id ?? "last_used",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,9 @@ const ASSIST_SCHEMA = [
|
|||||||
{
|
{
|
||||||
name: "pipeline_id",
|
name: "pipeline_id",
|
||||||
selector: {
|
selector: {
|
||||||
assist_pipeline: {},
|
assist_pipeline: {
|
||||||
|
include_last_used: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -567,7 +567,7 @@ class HUIRoot extends LitElement {
|
|||||||
if (searchParams.edit === "1") {
|
if (searchParams.edit === "1") {
|
||||||
this.lovelace!.setEditMode(true);
|
this.lovelace!.setEditMode(true);
|
||||||
} else if (searchParams.conversation === "1") {
|
} else if (searchParams.conversation === "1") {
|
||||||
showVoiceCommandDialog(this, this.hass);
|
this._showVoiceCommandDialog();
|
||||||
window.history.replaceState(
|
window.history.replaceState(
|
||||||
null,
|
null,
|
||||||
"",
|
"",
|
||||||
@ -793,7 +793,7 @@ class HUIRoot extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _showVoiceCommandDialog(): void {
|
private _showVoiceCommandDialog(): void {
|
||||||
showVoiceCommandDialog(this, this.hass);
|
showVoiceCommandDialog(this, this.hass, { pipeline_id: "last_used" });
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleEnableEditMode(ev: CustomEvent<RequestSelectedDetail>): void {
|
private _handleEnableEditMode(ev: CustomEvent<RequestSelectedDetail>): void {
|
||||||
|
@ -76,7 +76,7 @@ class PanelShoppingList extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _showVoiceCommandDialog(): void {
|
private _showVoiceCommandDialog(): void {
|
||||||
showVoiceCommandDialog(this, this.hass);
|
showVoiceCommandDialog(this, this.hass, { pipeline_id: "last_used" });
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
|
@ -398,7 +398,8 @@
|
|||||||
},
|
},
|
||||||
"pipeline-picker": {
|
"pipeline-picker": {
|
||||||
"pipeline": "Assistant",
|
"pipeline": "Assistant",
|
||||||
"preferred": "Preferred assistant ({preferred})"
|
"preferred": "Preferred assistant ({preferred})",
|
||||||
|
"last_used": "Last used assistant"
|
||||||
},
|
},
|
||||||
"theme-picker": {
|
"theme-picker": {
|
||||||
"theme": "Theme",
|
"theme": "Theme",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user