Skip to content

Commit

Permalink
implement wake_word/info command
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Sep 26, 2023
1 parent f4ed328 commit 161db47
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/data/wake_word.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { HomeAssistant } from "../types";

export interface WakeWord {
id: string;
name: string;
}

export const fetchWakeWordInfo = (hass: HomeAssistant, entity_id: string) =>
hass.callWS<{ wake_words: WakeWord[] }>({
type: "wake_word/info",
entity_id,
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import { LocalizeKeys } from "../../../../common/translations/localize";
import "../../../../components/ha-form/ha-form";
import { AssistPipeline } from "../../../../data/assist_pipeline";
import { HomeAssistant } from "../../../../types";
import { fetchWakeWordInfo, WakeWord } from "../../../../data/wake_word";

@customElement("assist-pipeline-detail-wakeword")
export class AssistPipelineDetailWakeWord extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@property() public data?: Partial<AssistPipeline>;

@state() private _wakeWords?: string[];
@state() private _wakeWords?: WakeWord[];

private _schema = memoizeOne(
(wakeWords?: string[]) =>
(wakeWords?: WakeWord[]) =>
[
{
name: "",
Expand All @@ -34,10 +35,15 @@ export class AssistPipelineDetailWakeWord extends LitElement {
name: "wake_word_id",
required: true,
selector: {
select: {},
select: {
options: wakeWords.map((ww) => ({
value: ww.id,
label: ww.name,
})),
},
},
}
: { name: "wake_word_id", selector: { text: {} } },
: { name: "", type: "constant" },
] as const,
},
] as const
Expand Down Expand Up @@ -89,11 +95,11 @@ export class AssistPipelineDetailWakeWord extends LitElement {
private async _fetchWakeWords() {
if (!this.data?.wake_word_entity) {
this._wakeWords = undefined;
// eslint-disable-next-line no-useless-return
return;
}
// to be implemented
// this._wakeWords = await fetchWakeWords(this.hass, this.data.wake_word_entity);
this._wakeWords = (
await fetchWakeWordInfo(this.hass, this.data.wake_word_entity)
).wake_words;
}

static get styles(): CSSResultGroup {
Expand Down
2 changes: 1 addition & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@
"tts_engine": "Text-to-speech",
"tts_language": "[%key:ui::panel::config::voice_assistants::assistants::pipeline::detail::form::language%]",
"tts_voice": "Voice",
"wake_word_entity": "Wake word library",
"wake_word_entity": "Wake word engine",
"wake_word_id": "Wake word"
},
"steps": {
Expand Down

0 comments on commit 161db47

Please sign in to comment.