Skip to content

Commit

Permalink
Add disable switch for exposing of new entities to assist
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede committed Dec 3, 2024
1 parent 1393a3a commit b719823
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
44 changes: 44 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 @@ -109,6 +124,23 @@ export class AssistPref extends LitElement {
></ha-icon-button>
</a>
</div>
<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>
<mwc-list>
${this._pipelines.map(
(pipeline) => html`
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
3 changes: 3 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit b719823

Please sign in to comment.