From b719823bbbe57712d5fa0c8b2de5df8c4c7cee40 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Tue, 3 Dec 2024 18:50:08 +0100 Subject: [PATCH 1/3] Add disable switch for exposing of new entities to assist --- .../config/voice-assistants/assist-pref.ts | 44 +++++++++++++++++++ src/translations/en.json | 3 ++ 2 files changed, 47 insertions(+) diff --git a/src/panels/config/voice-assistants/assist-pref.ts b/src/panels/config/voice-assistants/assist-pref.ts index 86c1f0a60bba..06e535f337b1 100644 --- a/src/panels/config/voice-assistants/assist-pref.ts +++ b/src/panels/config/voice-assistants/assist-pref.ts @@ -31,6 +31,10 @@ import { } from "../../../data/assist_pipeline"; import type { CloudStatus } from "../../../data/cloud"; import type { ExposeEntitySettings } from "../../../data/expose"; +import { + getExposeNewEntities, + setExposeNewEntities, +} from "../../../data/expose"; import { showAlertDialog, showConfirmationDialog, @@ -42,6 +46,7 @@ import { showVoiceAssistantPipelineDetailDialog } from "./show-dialog-voice-assi import { showVoiceCommandDialog } from "../../../dialogs/voice-command-dialog/show-ha-voice-command-dialog"; import { stopPropagation } from "../../../common/dom/stop_propagation"; import { computeDomain } from "../../../common/entity/compute_domain"; +import type { HaSwitch } from "../../../components/ha-switch"; import { navigate } from "../../../common/navigate"; @customElement("assist-pref") @@ -61,6 +66,16 @@ export class AssistPref extends LitElement { @state() private _pipelineEntitiesCount = 0; + @state() private _exposeNew?: boolean; + + protected willUpdate() { + if (!this.hasUpdated) { + getExposeNewEntities(this.hass, "conversation").then((value) => { + this._exposeNew = value.expose_new; + }); + } + } + protected firstUpdated(changedProps: PropertyValues) { super.firstUpdated(changedProps); @@ -109,6 +124,23 @@ export class AssistPref extends LitElement { > + + + ${this.hass!.localize( + "ui.panel.config.voice_assistants.expose.expose_new_entities" + )} + + + ${this.hass!.localize( + "ui.panel.config.voice_assistants.expose.expose_new_entities_info" + )} + + + ${this._pipelines.map( (pipeline) => html` @@ -225,6 +257,18 @@ export class AssistPref extends LitElement { `; } + private async _exposeNewToggleChanged(ev) { + const toggle = ev.target as HaSwitch; + if (this._exposeNew === undefined || this._exposeNew === toggle.checked) { + return; + } + try { + await setExposeNewEntities(this.hass, "conversation", toggle.checked); + } catch (err: any) { + toggle.checked = !toggle.checked; + } + } + private _talkWithPipeline(ev) { const id = ev.currentTarget.id as string; showVoiceCommandDialog(this, this.hass, { pipeline_id: id }); diff --git a/src/translations/en.json b/src/translations/en.json index e8bfe80a397a..88b7fed1a059 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2828,6 +2828,9 @@ "header": "Expose entities", "expose_to": "to {assistants}", "expose_entities": "Expose {count} {count, plural,\n one {entity}\n other {entities}\n}" + }, + "expose_new_entities": "Expose new entities", + "expose_new_entities_info": "Should new entities be exposed? Exposes supported devices that are not classified as security devices." } }, "satellite_wizard": { From d4cb58f46936b4c0d7bc6fde5a0b017fca7052f5 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Mon, 9 Dec 2024 13:11:59 +0100 Subject: [PATCH 2/3] Fix translation --- src/translations/en.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/translations/en.json b/src/translations/en.json index 88b7fed1a059..072288de550c 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2831,7 +2831,6 @@ }, "expose_new_entities": "Expose new entities", "expose_new_entities_info": "Should new entities be exposed? Exposes supported devices that are not classified as security devices." - } }, "satellite_wizard": { "skip": "Skip", From 4fcc3e0ea678c757538dd72f7677083dd3c54439 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Sun, 22 Dec 2024 17:00:02 +0100 Subject: [PATCH 3/3] Move to bottom and align assist row --- .../config/voice-assistants/assist-pref.ts | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/panels/config/voice-assistants/assist-pref.ts b/src/panels/config/voice-assistants/assist-pref.ts index 06e535f337b1..2bd6f1bb353d 100644 --- a/src/panels/config/voice-assistants/assist-pref.ts +++ b/src/panels/config/voice-assistants/assist-pref.ts @@ -124,23 +124,6 @@ export class AssistPref extends LitElement { > - - - ${this.hass!.localize( - "ui.panel.config.voice_assistants.expose.expose_new_entities" - )} - - - ${this.hass!.localize( - "ui.panel.config.voice_assistants.expose.expose_new_entities_info" - )} - - - ${this._pipelines.map( (pipeline) => html` @@ -225,6 +208,23 @@ export class AssistPref extends LitElement { )} + + + ${this.hass!.localize( + "ui.panel.config.voice_assistants.expose.expose_new_entities" + )} + + + ${this.hass!.localize( + "ui.panel.config.voice_assistants.expose.expose_new_entities_info" + )} + + +