Skip to content

Commit

Permalink
Add toggle switch for exposing of new entities to Assist (#23127)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede authored Dec 22, 2024
1 parent 8b63824 commit 14bebc7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/panels/config/voice-assistants/assist-pref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand All @@ -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);

Expand Down Expand Up @@ -193,6 +208,23 @@ export class AssistPref extends LitElement {
)}
<ha-svg-icon slot="icon" .path=${mdiPlus}></ha-svg-icon>
</ha-button>
<ha-settings-row>
<span slot="heading">
${this.hass!.localize(
"ui.panel.config.voice_assistants.expose.expose_new_entities"
)}
</span>
<span slot="description">
${this.hass!.localize(
"ui.panel.config.voice_assistants.expose.expose_new_entities_info"
)}
</span>
<ha-switch
.checked=${this._exposeNew}
.disabled=${this._exposeNew === undefined}
@change=${this._exposeNewToggleChanged}
></ha-switch>
</ha-settings-row>
<div class="card-actions">
<a
href="/config/voice-assistants/expose?assistants=conversation&historyBack"
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -332,6 +376,7 @@ export class AssistPref extends LitElement {
--mdc-list-item-meta-size: auto;
--mdc-list-item-meta-display: flex;
--mdc-list-side-padding-right: 8px;
--mdc-list-side-padding-left: 16px;
}
ha-list-item.danger {
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2843,7 +2843,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": {
"skip": "Skip",
Expand Down

0 comments on commit 14bebc7

Please sign in to comment.