mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
20230427.0 (#16338)
This commit is contained in:
commit
c50aad8403
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "home-assistant-frontend"
|
||||
version = "20230426.0"
|
||||
version = "20230427.0"
|
||||
license = {text = "Apache-2.0"}
|
||||
description = "The Home Assistant frontend"
|
||||
readme = "README.md"
|
||||
|
@ -666,6 +666,7 @@ export class HaDataTable extends LitElement {
|
||||
|
||||
.mdc-data-table__cell.mdc-data-table__cell--flex {
|
||||
display: flex;
|
||||
overflow: initial;
|
||||
}
|
||||
|
||||
.mdc-data-table__cell.mdc-data-table__cell--icon {
|
||||
|
@ -9,5 +9,11 @@ export interface AlexaEntity {
|
||||
export const fetchCloudAlexaEntities = (hass: HomeAssistant) =>
|
||||
hass.callWS<AlexaEntity[]>({ type: "cloud/alexa/entities" });
|
||||
|
||||
export const fetchCloudAlexaEntity = (hass: HomeAssistant, entity_id: string) =>
|
||||
hass.callWS<AlexaEntity>({
|
||||
type: "cloud/alexa/entities/get",
|
||||
entity_id,
|
||||
});
|
||||
|
||||
export const syncCloudAlexaEntities = (hass: HomeAssistant) =>
|
||||
hass.callWS({ type: "cloud/alexa/sync" });
|
||||
|
@ -27,7 +27,7 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
const statTypes: StatisticsTypes = ["min", "mean", "max"];
|
||||
const statTypes: StatisticsTypes = ["state", "min", "mean", "max"];
|
||||
|
||||
@customElement("ha-more-info-history")
|
||||
export class MoreInfoHistory extends LitElement {
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
ExtEntityRegistryEntry,
|
||||
} from "../../../data/entity_registry";
|
||||
import { voiceAssistants } from "../../../data/voice";
|
||||
import { haStyle, haStyleDialog } from "../../../resources/styles";
|
||||
import { haStyle } from "../../../resources/styles";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
import "./entity-voice-settings";
|
||||
import { ExposeEntityDialogParams } from "./show-dialog-expose-entity";
|
||||
@ -48,6 +48,11 @@ class DialogExposeEntity extends LitElement {
|
||||
"ui.panel.config.voice_assistants.expose.expose_dialog.header"
|
||||
);
|
||||
|
||||
const entities = this._filterEntities(
|
||||
this._params.extendedEntities,
|
||||
this._filter
|
||||
);
|
||||
|
||||
return html`
|
||||
<ha-dialog open @closed=${this.closeDialog} .heading=${header}>
|
||||
<div slot="heading">
|
||||
@ -76,10 +81,14 @@ class DialogExposeEntity extends LitElement {
|
||||
></search-input>
|
||||
</div>
|
||||
<mwc-list multi>
|
||||
${this._filterEntities(
|
||||
this._params.extendedEntities,
|
||||
this._filter
|
||||
).map((entity) => this._renderItem(entity))}
|
||||
<lit-virtualizer
|
||||
scroller
|
||||
class="ha-scrollbar"
|
||||
@click=${this._itemClicked}
|
||||
.items=${entities}
|
||||
.renderItem=${this._renderItem}
|
||||
>
|
||||
</lit-virtualizer>
|
||||
</mwc-list>
|
||||
<mwc-button
|
||||
slot="primaryAction"
|
||||
@ -95,10 +104,7 @@ class DialogExposeEntity extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
private _handleSelected(ev) {
|
||||
if (ev.detail.source !== "property") {
|
||||
return;
|
||||
}
|
||||
private _handleSelected = (ev) => {
|
||||
const entityId = ev.target.value;
|
||||
if (ev.detail.selected) {
|
||||
if (this._selected.includes(entityId)) {
|
||||
@ -108,6 +114,11 @@ class DialogExposeEntity extends LitElement {
|
||||
} else {
|
||||
this._selected = this._selected.filter((item) => item !== entityId);
|
||||
}
|
||||
};
|
||||
|
||||
private _itemClicked(ev) {
|
||||
const listItem = ev.target.closest("ha-check-list-item");
|
||||
listItem.selected = !listItem.selected;
|
||||
}
|
||||
|
||||
private _filterChanged(e) {
|
||||
@ -133,21 +144,23 @@ class DialogExposeEntity extends LitElement {
|
||||
|
||||
private _renderItem = (entity: ExtEntityRegistryEntry) => {
|
||||
const entityState = this.hass.states[entity.entity_id];
|
||||
return html`<ha-check-list-item
|
||||
graphic="icon"
|
||||
twoLine
|
||||
.value=${entity.entity_id}
|
||||
.selected=${this._selected.includes(entity.entity_id)}
|
||||
@request-selected=${this._handleSelected}
|
||||
>
|
||||
<ha-state-icon
|
||||
title=${ifDefined(entityState?.state)}
|
||||
slot="graphic"
|
||||
.state=${entityState}
|
||||
></ha-state-icon>
|
||||
${computeEntityRegistryName(this.hass!, entity)}
|
||||
<span slot="secondary">${entity.entity_id}</span>
|
||||
</ha-check-list-item>`;
|
||||
return html`
|
||||
<ha-check-list-item
|
||||
graphic="icon"
|
||||
twoLine
|
||||
.value=${entity.entity_id}
|
||||
.selected=${this._selected.includes(entity.entity_id)}
|
||||
@request-selected=${this._handleSelected}
|
||||
>
|
||||
<ha-state-icon
|
||||
title=${ifDefined(entityState?.state)}
|
||||
slot="graphic"
|
||||
.state=${entityState}
|
||||
></ha-state-icon>
|
||||
${computeEntityRegistryName(this.hass!, entity)}
|
||||
<span slot="secondary">${entity.entity_id}</span>
|
||||
</ha-check-list-item>
|
||||
`;
|
||||
};
|
||||
|
||||
private _expose() {
|
||||
@ -158,21 +171,36 @@ class DialogExposeEntity extends LitElement {
|
||||
static get styles(): CSSResultGroup {
|
||||
return [
|
||||
haStyle,
|
||||
haStyleDialog,
|
||||
css`
|
||||
ha-dialog {
|
||||
--dialog-content-padding: 0;
|
||||
--mdc-dialog-min-width: 500px;
|
||||
--mdc-dialog-max-width: 600px;
|
||||
}
|
||||
@media all and (min-width: 600px) {
|
||||
lit-virtualizer {
|
||||
height: 500px;
|
||||
}
|
||||
@media all and (max-width: 500px), all and (max-height: 800px) {
|
||||
ha-dialog {
|
||||
--mdc-dialog-min-width: 600px;
|
||||
--mdc-dialog-max-height: 80%;
|
||||
--mdc-dialog-min-width: calc(
|
||||
100vw - env(safe-area-inset-right) - env(safe-area-inset-left)
|
||||
);
|
||||
--mdc-dialog-max-width: calc(
|
||||
100vw - env(safe-area-inset-right) - env(safe-area-inset-left)
|
||||
);
|
||||
--mdc-dialog-min-height: 100%;
|
||||
--mdc-dialog-max-height: 100%;
|
||||
--vertical-align-dialog: flex-end;
|
||||
--ha-dialog-border-radius: 0px;
|
||||
}
|
||||
lit-virtualizer {
|
||||
height: calc(100vh - 234px);
|
||||
}
|
||||
}
|
||||
search-input {
|
||||
width: 100%;
|
||||
display: block;
|
||||
padding: 24px 16px 0;
|
||||
padding: 16px 16px 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.header {
|
||||
@ -231,6 +259,20 @@ class DialogExposeEntity extends LitElement {
|
||||
inset-inline-end: 16px;
|
||||
direction: var(--direction);
|
||||
}
|
||||
lit-virtualizer {
|
||||
width: 100%;
|
||||
contain: size layout !important;
|
||||
}
|
||||
ha-check-list-item {
|
||||
width: 100%;
|
||||
height: 72px;
|
||||
}
|
||||
ha-check-list-item ha-state-icon {
|
||||
margin-left: 24px;
|
||||
margin-inline-start: 24;
|
||||
margin-inline-end: initial;
|
||||
direction: var(--direction);
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
@ -1,9 +1,19 @@
|
||||
import {
|
||||
mdiBug,
|
||||
mdiClose,
|
||||
mdiDotsVertical,
|
||||
mdiStar,
|
||||
mdiStarOutline,
|
||||
} from "@mdi/js";
|
||||
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import { stopPropagation } from "../../../common/dom/stop_propagation";
|
||||
import { shouldHandleRequestSelectedEvent } from "../../../common/mwc/handle-request-selected-event";
|
||||
import { navigate } from "../../../common/navigate";
|
||||
import "../../../components/ha-button";
|
||||
import { createCloseHeading } from "../../../components/ha-dialog";
|
||||
import "../../../components/ha-form/ha-form";
|
||||
import "../../../components/ha-header-bar";
|
||||
import {
|
||||
AssistPipeline,
|
||||
AssistPipelineMutableParams,
|
||||
@ -11,8 +21,8 @@ import {
|
||||
} from "../../../data/assist_pipeline";
|
||||
import { haStyleDialog } from "../../../resources/styles";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
import "./assist-pipeline-detail/assist-pipeline-detail-conversation";
|
||||
import "./assist-pipeline-detail/assist-pipeline-detail-config";
|
||||
import "./assist-pipeline-detail/assist-pipeline-detail-conversation";
|
||||
import "./assist-pipeline-detail/assist-pipeline-detail-stt";
|
||||
import "./assist-pipeline-detail/assist-pipeline-detail-tts";
|
||||
import "./debug/assist-render-pipeline-events";
|
||||
@ -74,21 +84,62 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
const title = this._params.pipeline?.id
|
||||
? this._params.pipeline.name
|
||||
: this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.assistants.pipeline.detail.add_assistant_title"
|
||||
);
|
||||
|
||||
return html`
|
||||
<ha-dialog
|
||||
open
|
||||
@closed=${this.closeDialog}
|
||||
scrimClickAction
|
||||
escapeKeyAction
|
||||
.heading=${createCloseHeading(
|
||||
this.hass,
|
||||
this._params.pipeline?.id
|
||||
? this._params.pipeline.name
|
||||
: this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.assistants.pipeline.detail.add_assistant_title"
|
||||
)
|
||||
)}
|
||||
.heading=${title}
|
||||
>
|
||||
<ha-header-bar slot="heading">
|
||||
<ha-icon-button
|
||||
slot="navigationIcon"
|
||||
dialogAction="cancel"
|
||||
.label=${this.hass.localize("ui.common.close")}
|
||||
.path=${mdiClose}
|
||||
></ha-icon-button>
|
||||
<div slot="title" class="main-title" .title=${title}>${title}</div>
|
||||
${this._params.pipeline?.id
|
||||
? html`
|
||||
<ha-icon-button
|
||||
slot="actionItems"
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.assistants.pipeline.detail.set_as_preferred"
|
||||
)}
|
||||
.path=${this._preferred ? mdiStar : mdiStarOutline}
|
||||
@click=${this._setPreferred}
|
||||
.disabled=${Boolean(this._preferred)}
|
||||
></ha-icon-button>
|
||||
|
||||
<ha-button-menu
|
||||
corner="BOTTOM_END"
|
||||
menuCorner="END"
|
||||
slot="actionItems"
|
||||
@closed=${stopPropagation}
|
||||
fixed
|
||||
>
|
||||
<ha-icon-button
|
||||
slot="trigger"
|
||||
.label=${this.hass.localize("ui.common.menu")}
|
||||
.path=${mdiDotsVertical}
|
||||
></ha-icon-button>
|
||||
<ha-list-item graphic="icon" @request-selected=${this._debug}>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.assistants.pipeline.detail.debug"
|
||||
)}
|
||||
<ha-svg-icon slot="graphic" .path=${mdiBug}></ha-svg-icon>
|
||||
</ha-list-item>
|
||||
</ha-button-menu>
|
||||
`
|
||||
: nothing}
|
||||
</ha-header-bar>
|
||||
<div class="content">
|
||||
${this._error
|
||||
? html`<ha-alert alert-type="error">${this._error}</ha-alert>`
|
||||
@ -111,8 +162,8 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
|
||||
(this._data.tts_engine === "cloud" ||
|
||||
this._data.stt_engine === "cloud")
|
||||
? html`
|
||||
<ha-alert alert-type="warning"
|
||||
>${this.hass.localize(
|
||||
<ha-alert alert-type="warning">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.assistants.pipeline.detail.no_cloud_message"
|
||||
)}
|
||||
<a
|
||||
@ -152,19 +203,6 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
|
||||
>
|
||||
${this.hass.localize("ui.common.delete")}
|
||||
</ha-button>
|
||||
<ha-button
|
||||
.disabled=${this._preferred}
|
||||
slot="secondaryAction"
|
||||
@click=${this._setPreferred}
|
||||
>Set as preferred</ha-button
|
||||
>
|
||||
<a
|
||||
href="/config/voice-assistants/debug/${this._params.pipeline
|
||||
.id}"
|
||||
slot="secondaryAction"
|
||||
@click=${this.closeDialog}
|
||||
><ha-button>Debug</ha-button>
|
||||
</a>
|
||||
`
|
||||
: nothing}
|
||||
<ha-button
|
||||
@ -237,6 +275,12 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _debug(ev) {
|
||||
if (!shouldHandleRequestSelectedEvent(ev)) return;
|
||||
navigate(`/config/voice-assistants/debug/${this._params!.pipeline!.id}`);
|
||||
this.closeDialog();
|
||||
}
|
||||
|
||||
private async _deletePipeline() {
|
||||
this._submitting = true;
|
||||
try {
|
||||
@ -254,6 +298,15 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
|
||||
return [
|
||||
haStyleDialog,
|
||||
css`
|
||||
ha-header-bar {
|
||||
--mdc-theme-on-primary: var(--primary-text-color);
|
||||
--mdc-theme-primary: var(--mdc-theme-surface);
|
||||
display: block;
|
||||
}
|
||||
.main-title {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
assist-pipeline-detail-config,
|
||||
assist-pipeline-detail-conversation,
|
||||
assist-pipeline-detail-stt {
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import "../../../components/ha-aliases-editor";
|
||||
import "../../../components/ha-settings-row";
|
||||
import "../../../components/ha-switch";
|
||||
import { fetchCloudAlexaEntity } from "../../../data/alexa";
|
||||
import {
|
||||
CloudStatus,
|
||||
CloudStatusLoggedIn,
|
||||
@ -53,16 +54,16 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
|
||||
|
||||
@state() private _googleEntity?: GoogleEntity;
|
||||
|
||||
@state() private _unsupported: Partial<
|
||||
Record<"cloud.google_assistant" | "cloud.alexa" | "conversation", boolean>
|
||||
> = {};
|
||||
|
||||
protected willUpdate(changedProps: PropertyValues<this>) {
|
||||
if (!isComponentLoaded(this.hass, "cloud")) {
|
||||
return;
|
||||
}
|
||||
if (changedProps.has("entry") && this.entry) {
|
||||
fetchCloudGoogleEntity(this.hass, this.entry.entity_id).then(
|
||||
(googleEntity) => {
|
||||
this._googleEntity = googleEntity;
|
||||
}
|
||||
);
|
||||
this._fetchEntities();
|
||||
}
|
||||
if (!this.hasUpdated) {
|
||||
fetchCloudStatus(this.hass).then((status) => {
|
||||
@ -71,6 +72,31 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
}
|
||||
|
||||
private async _fetchEntities() {
|
||||
try {
|
||||
const googleEntity = await fetchCloudGoogleEntity(
|
||||
this.hass,
|
||||
this.entry.entity_id
|
||||
);
|
||||
this._googleEntity = googleEntity;
|
||||
this.requestUpdate("_googleEntity");
|
||||
} catch (err: any) {
|
||||
if (err.code === "not_supported") {
|
||||
this._unsupported["cloud.google_assistant"] = true;
|
||||
this.requestUpdate("_unsupported");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await fetchCloudAlexaEntity(this.hass, this.entry.entity_id);
|
||||
} catch (err: any) {
|
||||
if (err.code === "not_supported") {
|
||||
this._unsupported["cloud.alexa"] = true;
|
||||
this.requestUpdate("_unsupported");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _getEntityFilterFuncs = memoizeOne(
|
||||
(googleFilter: EntityFilter, alexaFilter: EntityFilter) => ({
|
||||
google: generateFilter(
|
||||
@ -163,9 +189,28 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
|
||||
></ha-switch>
|
||||
</ha-settings-row>
|
||||
${anyExposed
|
||||
? showAssistants.map(
|
||||
(key) => html`
|
||||
<ha-settings-row>
|
||||
? showAssistants.map((key) => {
|
||||
const supported = !this._unsupported[key];
|
||||
|
||||
const exposed =
|
||||
alexaManual && key === "cloud.alexa"
|
||||
? manExposedAlexa
|
||||
: googleManual && key === "cloud.google_assistant"
|
||||
? manExposedGoogle
|
||||
: this.entry.options?.[key]?.should_expose;
|
||||
|
||||
const manualConfig =
|
||||
(alexaManual && key === "cloud.alexa") ||
|
||||
(googleManual && key === "cloud.google_assistant");
|
||||
|
||||
const support2fa =
|
||||
key === "cloud.google_assistant" &&
|
||||
!googleManual &&
|
||||
supported &&
|
||||
this._googleEntity?.might_2fa;
|
||||
|
||||
return html`
|
||||
<ha-settings-row .threeLine=${!supported && manualConfig}>
|
||||
<img
|
||||
alt=""
|
||||
src=${brandsUrl({
|
||||
@ -177,9 +222,23 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
|
||||
slot="prefix"
|
||||
/>
|
||||
<span slot="heading">${voiceAssistants[key].name}</span>
|
||||
${key === "cloud.google_assistant" &&
|
||||
!googleManual &&
|
||||
this._googleEntity?.might_2fa
|
||||
${!supported
|
||||
? html`<div slot="description">
|
||||
${this.hass.localize(
|
||||
"ui.dialogs.voice-settings.unsupported"
|
||||
)}
|
||||
</div>`
|
||||
: nothing}
|
||||
${manualConfig
|
||||
? html`
|
||||
<div slot="description">
|
||||
${this.hass.localize(
|
||||
"ui.dialogs.voice-settings.manual_config"
|
||||
)}
|
||||
</div>
|
||||
`
|
||||
: nothing}
|
||||
${support2fa
|
||||
? html`
|
||||
<ha-formfield
|
||||
slot="description"
|
||||
@ -193,30 +252,16 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
|
||||
></ha-checkbox>
|
||||
</ha-formfield>
|
||||
`
|
||||
: (alexaManual && key === "cloud.alexa") ||
|
||||
(googleManual && key === "cloud.google_assistant")
|
||||
? html`
|
||||
<span slot="description">
|
||||
${this.hass.localize(
|
||||
"ui.dialogs.voice-settings.manual_config"
|
||||
)}
|
||||
</span>
|
||||
`
|
||||
: nothing}
|
||||
<ha-switch
|
||||
.assistant=${key}
|
||||
@change=${this._toggleAssistant}
|
||||
.disabled=${(alexaManual && key === "cloud.alexa") ||
|
||||
(googleManual && key === "cloud.google_assistant")}
|
||||
.checked=${alexaManual && key === "cloud.alexa"
|
||||
? manExposedAlexa
|
||||
: googleManual && key === "cloud.google_assistant"
|
||||
? manExposedGoogle
|
||||
: this.entry.options?.[key]?.should_expose}
|
||||
.disabled=${manualConfig || (!exposed && !supported)}
|
||||
.checked=${exposed}
|
||||
></ha-switch>
|
||||
</ha-settings-row>
|
||||
`
|
||||
)
|
||||
`;
|
||||
})
|
||||
: nothing}
|
||||
|
||||
<h3 class="header">
|
||||
@ -283,9 +328,15 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
|
||||
private async _toggleAll(ev) {
|
||||
const expose = ev.target.checked;
|
||||
|
||||
const assistants = expose
|
||||
? ev.target.assistants.filter((key) => !this._unsupported[key])
|
||||
: ev.target.assistants;
|
||||
|
||||
exposeEntities(
|
||||
this.hass,
|
||||
ev.target.assistants,
|
||||
assistants,
|
||||
[this.entry.entity_id],
|
||||
ev.target.checked
|
||||
);
|
||||
@ -305,6 +356,7 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
|
||||
margin: 32px;
|
||||
margin-top: 0;
|
||||
--settings-row-prefix-display: contents;
|
||||
--settings-row-content-display: contents;
|
||||
}
|
||||
ha-settings-row {
|
||||
padding: 0;
|
||||
|
@ -0,0 +1,102 @@
|
||||
import "@lrnwebcomponents/simple-tooltip/simple-tooltip";
|
||||
import { mdiAlertCircle } from "@mdi/js";
|
||||
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { voiceAssistants } from "../../../../data/voice";
|
||||
import { HomeAssistant } from "../../../../types";
|
||||
import { brandsUrl } from "../../../../util/brands-url";
|
||||
import "../../../../components/ha-svg-icon";
|
||||
|
||||
@customElement("voice-assistants-expose-assistant-icon")
|
||||
export class VoiceAssistantExposeAssistantIcon extends LitElement {
|
||||
@property() public hass!: HomeAssistant;
|
||||
|
||||
@property({ type: Boolean }) public unsupported!: boolean;
|
||||
|
||||
@property({ type: Boolean }) public manual?: boolean;
|
||||
|
||||
@property() public assistant?:
|
||||
| "conversation"
|
||||
| "cloud.alexa"
|
||||
| "cloud.google_assistant";
|
||||
|
||||
render() {
|
||||
if (!this.assistant || !voiceAssistants[this.assistant]) return nothing;
|
||||
|
||||
return html`
|
||||
<div class="container">
|
||||
<img
|
||||
class="logo"
|
||||
style=${styleMap({
|
||||
filter: this.manual ? "grayscale(100%)" : undefined,
|
||||
})}
|
||||
alt=""
|
||||
src=${brandsUrl({
|
||||
domain: voiceAssistants[this.assistant].domain,
|
||||
type: "icon",
|
||||
darkOptimized: this.hass.themes?.darkMode,
|
||||
})}
|
||||
referrerpolicy="no-referrer"
|
||||
slot="prefix"
|
||||
/>
|
||||
${this.unsupported
|
||||
? html`
|
||||
<ha-svg-icon
|
||||
.path=${mdiAlertCircle}
|
||||
class="unsupported"
|
||||
></ha-svg-icon>
|
||||
`
|
||||
: nothing}
|
||||
${this.manual || this.unsupported
|
||||
? html`
|
||||
<simple-tooltip
|
||||
animation-delay="0"
|
||||
position="top"
|
||||
offset="4"
|
||||
fitToVisibleBounds
|
||||
>
|
||||
${this.unsupported
|
||||
? this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.expose.not_supported"
|
||||
)
|
||||
: ""}
|
||||
${this.unsupported && this.manual ? html`<br />` : nothing}
|
||||
${this.manual
|
||||
? this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.expose.manually_configured"
|
||||
)
|
||||
: nothing}
|
||||
</simple-tooltip>
|
||||
`
|
||||
: ""}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
.container {
|
||||
position: relative;
|
||||
}
|
||||
.logo {
|
||||
position: relative;
|
||||
height: 24px;
|
||||
margin-right: 16px;
|
||||
}
|
||||
.unsupported {
|
||||
color: var(--error-color);
|
||||
position: absolute;
|
||||
--mdc-icon-size: 16px;
|
||||
right: 10px;
|
||||
top: -7px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"voice-assistants-expose-assistant-icon": VoiceAssistantExposeAssistantIcon;
|
||||
}
|
||||
}
|
@ -3,14 +3,21 @@ import "@lrnwebcomponents/simple-tooltip/simple-tooltip";
|
||||
import {
|
||||
mdiCloseBoxMultiple,
|
||||
mdiCloseCircleOutline,
|
||||
mdiFilterVariant,
|
||||
mdiPlus,
|
||||
mdiPlusBoxMultiple,
|
||||
} from "@mdi/js";
|
||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
||||
import {
|
||||
css,
|
||||
CSSResultGroup,
|
||||
html,
|
||||
LitElement,
|
||||
nothing,
|
||||
PropertyValues,
|
||||
} from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import memoize from "memoize-one";
|
||||
import { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||
import {
|
||||
@ -27,6 +34,7 @@ import {
|
||||
SelectionChangedEvent,
|
||||
} from "../../../components/data-table/ha-data-table";
|
||||
import "../../../components/ha-fab";
|
||||
import { AlexaEntity, fetchCloudAlexaEntities } from "../../../data/alexa";
|
||||
import { CloudStatus, CloudStatusLoggedIn } from "../../../data/cloud";
|
||||
import { entitiesContext } from "../../../data/context";
|
||||
import {
|
||||
@ -35,6 +43,10 @@ import {
|
||||
ExtEntityRegistryEntry,
|
||||
getExtendedEntityRegistryEntries,
|
||||
} from "../../../data/entity_registry";
|
||||
import {
|
||||
fetchCloudGoogleEntities,
|
||||
GoogleEntity,
|
||||
} from "../../../data/google_assistant";
|
||||
import { exposeEntities, voiceAssistants } from "../../../data/voice";
|
||||
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||
import "../../../layouts/hass-loading-screen";
|
||||
@ -42,10 +54,10 @@ import "../../../layouts/hass-tabs-subpage-data-table";
|
||||
import type { HaTabsSubpageDataTable } from "../../../layouts/hass-tabs-subpage-data-table";
|
||||
import { haStyle } from "../../../resources/styles";
|
||||
import { HomeAssistant, Route } from "../../../types";
|
||||
import { brandsUrl } from "../../../util/brands-url";
|
||||
import { voiceAssistantTabs } from "./ha-config-voice-assistants";
|
||||
import { showExposeEntityDialog } from "./show-dialog-expose-entity";
|
||||
import { showVoiceSettingsDialog } from "./show-dialog-voice-settings";
|
||||
import "./expose/expose-assistant-icon";
|
||||
|
||||
@customElement("ha-config-voice-assistants-expose")
|
||||
export class VoiceAssistantsExpose extends LitElement {
|
||||
@ -73,6 +85,11 @@ export class VoiceAssistantsExpose extends LitElement {
|
||||
|
||||
@state() private _selectedEntities: string[] = [];
|
||||
|
||||
@state() private _supportedEntities?: Record<
|
||||
"cloud.google_assistant" | "cloud.alexa" | "conversation",
|
||||
string[] | undefined
|
||||
>;
|
||||
|
||||
@query("hass-tabs-subpage-data-table", true)
|
||||
private _dataTable!: HaTabsSubpageDataTable;
|
||||
|
||||
@ -139,35 +156,23 @@ export class VoiceAssistantsExpose extends LitElement {
|
||||
width: "160px",
|
||||
type: "flex",
|
||||
template: (assistants, entry) =>
|
||||
html`${availableAssistants.map((key) =>
|
||||
assistants.includes(key)
|
||||
? html`<div>
|
||||
<img
|
||||
style="height: 24px; margin-right: 16px;${styleMap({
|
||||
filter: entry.manAssistants?.includes(key)
|
||||
? "grayscale(100%)"
|
||||
: "",
|
||||
})}"
|
||||
alt=""
|
||||
src=${brandsUrl({
|
||||
domain: voiceAssistants[key].domain,
|
||||
type: "icon",
|
||||
darkOptimized: this.hass.themes?.darkMode,
|
||||
})}
|
||||
referrerpolicy="no-referrer"
|
||||
slot="prefix"
|
||||
/>${entry.manAssistants?.includes(key)
|
||||
? html`<simple-tooltip
|
||||
animation-delay="0"
|
||||
position="bottom"
|
||||
offset="1"
|
||||
>
|
||||
Configured in YAML, not editable in UI
|
||||
</simple-tooltip>`
|
||||
: ""}
|
||||
</div>`
|
||||
: html`<div style="width: 40px;"></div>`
|
||||
)}`,
|
||||
html`${availableAssistants.map((key) => {
|
||||
const supported =
|
||||
!this._supportedEntities?.[key] ||
|
||||
this._supportedEntities[key].includes(entry.entity_id);
|
||||
const manual = entry.manAssistants?.includes(key);
|
||||
return assistants.includes(key)
|
||||
? html`
|
||||
<voice-assistants-expose-assistant-icon
|
||||
.assistant=${key}
|
||||
.hass=${this.hass}
|
||||
.manual=${manual}
|
||||
.unsupported=${!supported}
|
||||
>
|
||||
</voice-assistants-expose-assistant-icon>
|
||||
`
|
||||
: html`<div style="width: 40px;"></div>`;
|
||||
})}`,
|
||||
},
|
||||
aliases: {
|
||||
title: this.hass.localize(
|
||||
@ -197,6 +202,12 @@ export class VoiceAssistantsExpose extends LitElement {
|
||||
.path=${mdiCloseCircleOutline}
|
||||
></ha-icon-button>`,
|
||||
},
|
||||
// For search
|
||||
entity_id: {
|
||||
title: "",
|
||||
hidden: true,
|
||||
filterable: true,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
@ -423,16 +434,36 @@ export class VoiceAssistantsExpose extends LitElement {
|
||||
});
|
||||
}
|
||||
|
||||
private async _fetchExtendedEntities() {
|
||||
private async _fetchEntities() {
|
||||
this._extEntities = await getExtendedEntityRegistryEntries(
|
||||
this.hass,
|
||||
Object.keys(this._entities)
|
||||
);
|
||||
let alexaEntitiesProm: Promise<AlexaEntity[]> | undefined;
|
||||
let googleEntitiesProm: Promise<GoogleEntity[]> | undefined;
|
||||
if (this.cloudStatus?.logged_in && this.cloudStatus.prefs.alexa_enabled) {
|
||||
alexaEntitiesProm = fetchCloudAlexaEntities(this.hass);
|
||||
}
|
||||
if (this.cloudStatus?.logged_in && this.cloudStatus.prefs.google_enabled) {
|
||||
googleEntitiesProm = fetchCloudGoogleEntities(this.hass);
|
||||
}
|
||||
const [alexaEntities, googleEntities] = await Promise.all([
|
||||
alexaEntitiesProm,
|
||||
googleEntitiesProm,
|
||||
]);
|
||||
this._supportedEntities = {
|
||||
"cloud.alexa": alexaEntities?.map((entity) => entity.entity_id),
|
||||
"cloud.google_assistant": googleEntities?.map(
|
||||
(entity) => entity.entity_id
|
||||
),
|
||||
// TODO add supported entity for assit
|
||||
conversation: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
public willUpdate(changedProperties: PropertyValues): void {
|
||||
if (changedProperties.has("_entities")) {
|
||||
this._fetchExtendedEntities();
|
||||
this._fetchEntities();
|
||||
}
|
||||
}
|
||||
|
||||
@ -560,6 +591,26 @@ export class VoiceAssistantsExpose extends LitElement {
|
||||
>
|
||||
<ha-svg-icon slot="icon" .path=${mdiPlus}></ha-svg-icon>
|
||||
</ha-fab>
|
||||
${this.narrow && activeFilters?.length
|
||||
? html`
|
||||
<ha-button-menu slot="filter-menu" multi>
|
||||
<ha-icon-button
|
||||
slot="trigger"
|
||||
.label=${this.hass!.localize(
|
||||
"ui.panel.config.devices.picker.filter.filter"
|
||||
)}
|
||||
.path=${mdiFilterVariant}
|
||||
></ha-icon-button>
|
||||
<mwc-list-item @click=${this._clearFilter}>
|
||||
${this.hass.localize("ui.components.data-table.filtering_by")}
|
||||
${activeFilters.join(", ")}
|
||||
<span class="clear">
|
||||
${this.hass.localize("ui.common.clear")}
|
||||
</span>
|
||||
</mwc-list-item>
|
||||
</ha-button-menu>
|
||||
`
|
||||
: nothing}
|
||||
</hass-tabs-subpage-data-table>
|
||||
`;
|
||||
}
|
||||
|
@ -1083,7 +1083,8 @@
|
||||
"aliases_header": "Aliases",
|
||||
"aliases_description": "Aliases are supported by Assist and Google Assistant.",
|
||||
"ask_pin": "Ask for PIN",
|
||||
"manual_config": "Managed with filters in configuration.yaml"
|
||||
"manual_config": "Managed in configuration.yaml",
|
||||
"unsupported": "Unsupported"
|
||||
},
|
||||
"restart": {
|
||||
"heading": "Restart Home Assistant",
|
||||
@ -2039,6 +2040,8 @@
|
||||
"add_assistant_title": "Add assistant",
|
||||
"add_assistant_action": "Create",
|
||||
"try_tts": "Try voice",
|
||||
"debug": "Debug",
|
||||
"set_as_preferred": "Set as preferred",
|
||||
"form": {
|
||||
"name": "Name",
|
||||
"conversation_engine": "Conversation agent",
|
||||
@ -2105,6 +2108,8 @@
|
||||
"expose_confirm_text": "Do you want to expose {entities} entities to {assistants}?",
|
||||
"unexpose_confirm_title": "Stop exposing selected entities?",
|
||||
"unexpose_confirm_text": "Do you want to stop exposing {entities} entities to {assistants}?",
|
||||
"manually_configured": "Configured in YAML, not editable in UI",
|
||||
"not_supported": "Not supported by this assistant",
|
||||
"expose_dialog": {
|
||||
"header": "Expose entities",
|
||||
"expose_to": "to {assistants}",
|
||||
|
@ -16585,9 +16585,9 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"yaml@npm:^2.2.1":
|
||||
version: 2.2.1
|
||||
resolution: "yaml@npm:2.2.1"
|
||||
checksum: 84f68cbe462d5da4e7ded4a8bded949ffa912bc264472e5a684c3d45b22d8f73a3019963a32164023bdf3d83cfb6f5b58ff7b2b10ef5b717c630f40bd6369a23
|
||||
version: 2.2.2
|
||||
resolution: "yaml@npm:2.2.2"
|
||||
checksum: d90c235e099e30094dcff61ba3350437aef53325db4a6bcd04ca96e1bfe7e348b191f6a7a52b5211e2dbc4eeedb22a00b291527da030de7c189728ef3f2b4eb3
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user