Skip to content

Commit

Permalink
Link to docs when no wake word engines (#18046)
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored Sep 28, 2023
1 parent c5f909d commit 30c6e4e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
import {
css,
CSSResultGroup,
html,
LitElement,
nothing,
PropertyValues,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
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";
import { documentationUrl } from "../../../../util/documentation-url";

@customElement("assist-pipeline-detail-wakeword")
export class AssistPipelineDetailWakeWord extends LitElement {
Expand Down Expand Up @@ -67,7 +75,12 @@ export class AssistPipelineDetailWakeWord extends LitElement {
}
}

private _hasWakeWorkEntities = memoizeOne((states: HomeAssistant["states"]) =>
Object.keys(states).some((entityId) => entityId.startsWith("wake_word."))
);

protected render() {
const hasWakeWorkEntities = this._hasWakeWorkEntities(this.hass.states);
return html`
<div class="section">
<div class="content">
Expand All @@ -83,11 +96,25 @@ export class AssistPipelineDetailWakeWord extends LitElement {
)}
</p>
</div>
${!hasWakeWorkEntities
? html`${this.hass.localize(
`ui.panel.config.voice_assistants.assistants.pipeline.detail.steps.wakeword.no_wake_words`
)}
<a
href=${documentationUrl(this.hass, "/docs/assist/")}
target="_blank"
rel="noreferrer noopener"
>${this.hass.localize(
`ui.panel.config.voice_assistants.assistants.pipeline.detail.steps.wakeword.no_wake_words_link`
)}</a
>`
: nothing}
<ha-form
.schema=${this._schema(this._wakeWords)}
.data=${this.data}
.hass=${this.hass}
.computeLabel=${this._computeLabel}
.disabled=${!hasWakeWorkEntities}
></ha-form>
</div>
</div>
Expand Down Expand Up @@ -129,6 +156,9 @@ export class AssistPipelineDetailWakeWord extends LitElement {
margin-top: 0;
margin-bottom: 0;
}
a {
color: var(--primary-color);
}
`;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/panels/config/voice-assistants/assist-pref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box
import type { HomeAssistant } from "../../../types";
import { brandsUrl } from "../../../util/brands-url";
import { showVoiceAssistantPipelineDetailDialog } from "./show-dialog-voice-assistant-pipeline-detail";
import { documentationUrl } from "../../../util/documentation-url";

export class AssistPref extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand Down Expand Up @@ -73,9 +74,9 @@ export class AssistPref extends LitElement {
</h1>
<div class="header-actions">
<a
href="https://www.home-assistant.io/docs/assist/"
href=${documentationUrl(this.hass, "/docs/assist/")}
target="_blank"
rel="noreferrer"
rel="noreferrer noopener"
class="icon-link"
>
<ha-icon-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,7 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
return [
haStyleDialog,
css`
assist-pipeline-detail-config,
assist-pipeline-detail-conversation,
assist-pipeline-detail-stt {
.content > *:not(:last-child) {
margin-bottom: 16px;
display: block;
}
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,9 @@
},
"wakeword": {
"title": "Wake word",
"description": "If a device supports wake words, you can activate Assist by saying this word."
"description": "If a device supports wake words, you can activate Assist by saying this word.",
"no_wake_words": "It looks like you don't have a wake word engine setup yet.",
"no_wake_words_link": "Find out more about wake words."
}
},
"no_cloud_message": "You should have an active cloud subscription to use cloud speech services.",
Expand Down

0 comments on commit 30c6e4e

Please sign in to comment.