20230427.0 (#16338)

This commit is contained in:
Paul Bottein 2023-04-27 17:31:29 +02:00 committed by GitHub
commit c50aad8403
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 436 additions and 124 deletions

View File

@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "home-assistant-frontend" name = "home-assistant-frontend"
version = "20230426.0" version = "20230427.0"
license = {text = "Apache-2.0"} license = {text = "Apache-2.0"}
description = "The Home Assistant frontend" description = "The Home Assistant frontend"
readme = "README.md" readme = "README.md"

View File

@ -666,6 +666,7 @@ export class HaDataTable extends LitElement {
.mdc-data-table__cell.mdc-data-table__cell--flex { .mdc-data-table__cell.mdc-data-table__cell--flex {
display: flex; display: flex;
overflow: initial;
} }
.mdc-data-table__cell.mdc-data-table__cell--icon { .mdc-data-table__cell.mdc-data-table__cell--icon {

View File

@ -9,5 +9,11 @@ export interface AlexaEntity {
export const fetchCloudAlexaEntities = (hass: HomeAssistant) => export const fetchCloudAlexaEntities = (hass: HomeAssistant) =>
hass.callWS<AlexaEntity[]>({ type: "cloud/alexa/entities" }); 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) => export const syncCloudAlexaEntities = (hass: HomeAssistant) =>
hass.callWS({ type: "cloud/alexa/sync" }); hass.callWS({ type: "cloud/alexa/sync" });

View File

@ -27,7 +27,7 @@ declare global {
} }
} }
const statTypes: StatisticsTypes = ["min", "mean", "max"]; const statTypes: StatisticsTypes = ["state", "min", "mean", "max"];
@customElement("ha-more-info-history") @customElement("ha-more-info-history")
export class MoreInfoHistory extends LitElement { export class MoreInfoHistory extends LitElement {

View File

@ -13,7 +13,7 @@ import {
ExtEntityRegistryEntry, ExtEntityRegistryEntry,
} from "../../../data/entity_registry"; } from "../../../data/entity_registry";
import { voiceAssistants } from "../../../data/voice"; import { voiceAssistants } from "../../../data/voice";
import { haStyle, haStyleDialog } from "../../../resources/styles"; import { haStyle } from "../../../resources/styles";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import "./entity-voice-settings"; import "./entity-voice-settings";
import { ExposeEntityDialogParams } from "./show-dialog-expose-entity"; import { ExposeEntityDialogParams } from "./show-dialog-expose-entity";
@ -48,6 +48,11 @@ class DialogExposeEntity extends LitElement {
"ui.panel.config.voice_assistants.expose.expose_dialog.header" "ui.panel.config.voice_assistants.expose.expose_dialog.header"
); );
const entities = this._filterEntities(
this._params.extendedEntities,
this._filter
);
return html` return html`
<ha-dialog open @closed=${this.closeDialog} .heading=${header}> <ha-dialog open @closed=${this.closeDialog} .heading=${header}>
<div slot="heading"> <div slot="heading">
@ -76,10 +81,14 @@ class DialogExposeEntity extends LitElement {
></search-input> ></search-input>
</div> </div>
<mwc-list multi> <mwc-list multi>
${this._filterEntities( <lit-virtualizer
this._params.extendedEntities, scroller
this._filter class="ha-scrollbar"
).map((entity) => this._renderItem(entity))} @click=${this._itemClicked}
.items=${entities}
.renderItem=${this._renderItem}
>
</lit-virtualizer>
</mwc-list> </mwc-list>
<mwc-button <mwc-button
slot="primaryAction" slot="primaryAction"
@ -95,10 +104,7 @@ class DialogExposeEntity extends LitElement {
`; `;
} }
private _handleSelected(ev) { private _handleSelected = (ev) => {
if (ev.detail.source !== "property") {
return;
}
const entityId = ev.target.value; const entityId = ev.target.value;
if (ev.detail.selected) { if (ev.detail.selected) {
if (this._selected.includes(entityId)) { if (this._selected.includes(entityId)) {
@ -108,6 +114,11 @@ class DialogExposeEntity extends LitElement {
} else { } else {
this._selected = this._selected.filter((item) => item !== entityId); 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) { private _filterChanged(e) {
@ -133,21 +144,23 @@ class DialogExposeEntity extends LitElement {
private _renderItem = (entity: ExtEntityRegistryEntry) => { private _renderItem = (entity: ExtEntityRegistryEntry) => {
const entityState = this.hass.states[entity.entity_id]; const entityState = this.hass.states[entity.entity_id];
return html`<ha-check-list-item return html`
graphic="icon" <ha-check-list-item
twoLine graphic="icon"
.value=${entity.entity_id} twoLine
.selected=${this._selected.includes(entity.entity_id)} .value=${entity.entity_id}
@request-selected=${this._handleSelected} .selected=${this._selected.includes(entity.entity_id)}
> @request-selected=${this._handleSelected}
<ha-state-icon >
title=${ifDefined(entityState?.state)} <ha-state-icon
slot="graphic" title=${ifDefined(entityState?.state)}
.state=${entityState} slot="graphic"
></ha-state-icon> .state=${entityState}
${computeEntityRegistryName(this.hass!, entity)} ></ha-state-icon>
<span slot="secondary">${entity.entity_id}</span> ${computeEntityRegistryName(this.hass!, entity)}
</ha-check-list-item>`; <span slot="secondary">${entity.entity_id}</span>
</ha-check-list-item>
`;
}; };
private _expose() { private _expose() {
@ -158,21 +171,36 @@ class DialogExposeEntity extends LitElement {
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return [ return [
haStyle, haStyle,
haStyleDialog,
css` css`
ha-dialog { ha-dialog {
--dialog-content-padding: 0; --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 { ha-dialog {
--mdc-dialog-min-width: 600px; --mdc-dialog-min-width: calc(
--mdc-dialog-max-height: 80%; 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 { search-input {
width: 100%; width: 100%;
display: block; display: block;
padding: 24px 16px 0; padding: 16px 16px 0;
box-sizing: border-box; box-sizing: border-box;
} }
.header { .header {
@ -231,6 +259,20 @@ class DialogExposeEntity extends LitElement {
inset-inline-end: 16px; inset-inline-end: 16px;
direction: var(--direction); 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);
}
`, `,
]; ];
} }

View File

@ -1,9 +1,19 @@
import {
mdiBug,
mdiClose,
mdiDotsVertical,
mdiStar,
mdiStarOutline,
} from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../../common/dom/fire_event"; 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 "../../../components/ha-button";
import { createCloseHeading } from "../../../components/ha-dialog";
import "../../../components/ha-form/ha-form"; import "../../../components/ha-form/ha-form";
import "../../../components/ha-header-bar";
import { import {
AssistPipeline, AssistPipeline,
AssistPipelineMutableParams, AssistPipelineMutableParams,
@ -11,8 +21,8 @@ import {
} from "../../../data/assist_pipeline"; } from "../../../data/assist_pipeline";
import { haStyleDialog } from "../../../resources/styles"; import { haStyleDialog } from "../../../resources/styles";
import { HomeAssistant } from "../../../types"; 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-config";
import "./assist-pipeline-detail/assist-pipeline-detail-conversation";
import "./assist-pipeline-detail/assist-pipeline-detail-stt"; import "./assist-pipeline-detail/assist-pipeline-detail-stt";
import "./assist-pipeline-detail/assist-pipeline-detail-tts"; import "./assist-pipeline-detail/assist-pipeline-detail-tts";
import "./debug/assist-render-pipeline-events"; import "./debug/assist-render-pipeline-events";
@ -74,21 +84,62 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
return nothing; 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` return html`
<ha-dialog <ha-dialog
open open
@closed=${this.closeDialog} @closed=${this.closeDialog}
scrimClickAction scrimClickAction
escapeKeyAction escapeKeyAction
.heading=${createCloseHeading( .heading=${title}
this.hass,
this._params.pipeline?.id
? this._params.pipeline.name
: this.hass.localize(
"ui.panel.config.voice_assistants.assistants.pipeline.detail.add_assistant_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"> <div class="content">
${this._error ${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` ? 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.tts_engine === "cloud" ||
this._data.stt_engine === "cloud") this._data.stt_engine === "cloud")
? html` ? html`
<ha-alert alert-type="warning" <ha-alert alert-type="warning">
>${this.hass.localize( ${this.hass.localize(
"ui.panel.config.voice_assistants.assistants.pipeline.detail.no_cloud_message" "ui.panel.config.voice_assistants.assistants.pipeline.detail.no_cloud_message"
)} )}
<a <a
@ -152,19 +203,6 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
> >
${this.hass.localize("ui.common.delete")} ${this.hass.localize("ui.common.delete")}
</ha-button> </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} : nothing}
<ha-button <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() { private async _deletePipeline() {
this._submitting = true; this._submitting = true;
try { try {
@ -254,6 +298,15 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
return [ return [
haStyleDialog, haStyleDialog,
css` 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-config,
assist-pipeline-detail-conversation, assist-pipeline-detail-conversation,
assist-pipeline-detail-stt { assist-pipeline-detail-stt {

View File

@ -19,6 +19,7 @@ import {
import "../../../components/ha-aliases-editor"; import "../../../components/ha-aliases-editor";
import "../../../components/ha-settings-row"; import "../../../components/ha-settings-row";
import "../../../components/ha-switch"; import "../../../components/ha-switch";
import { fetchCloudAlexaEntity } from "../../../data/alexa";
import { import {
CloudStatus, CloudStatus,
CloudStatusLoggedIn, CloudStatusLoggedIn,
@ -53,16 +54,16 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
@state() private _googleEntity?: GoogleEntity; @state() private _googleEntity?: GoogleEntity;
@state() private _unsupported: Partial<
Record<"cloud.google_assistant" | "cloud.alexa" | "conversation", boolean>
> = {};
protected willUpdate(changedProps: PropertyValues<this>) { protected willUpdate(changedProps: PropertyValues<this>) {
if (!isComponentLoaded(this.hass, "cloud")) { if (!isComponentLoaded(this.hass, "cloud")) {
return; return;
} }
if (changedProps.has("entry") && this.entry) { if (changedProps.has("entry") && this.entry) {
fetchCloudGoogleEntity(this.hass, this.entry.entity_id).then( this._fetchEntities();
(googleEntity) => {
this._googleEntity = googleEntity;
}
);
} }
if (!this.hasUpdated) { if (!this.hasUpdated) {
fetchCloudStatus(this.hass).then((status) => { 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( private _getEntityFilterFuncs = memoizeOne(
(googleFilter: EntityFilter, alexaFilter: EntityFilter) => ({ (googleFilter: EntityFilter, alexaFilter: EntityFilter) => ({
google: generateFilter( google: generateFilter(
@ -163,9 +189,28 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
></ha-switch> ></ha-switch>
</ha-settings-row> </ha-settings-row>
${anyExposed ${anyExposed
? showAssistants.map( ? showAssistants.map((key) => {
(key) => html` const supported = !this._unsupported[key];
<ha-settings-row>
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 <img
alt="" alt=""
src=${brandsUrl({ src=${brandsUrl({
@ -177,9 +222,23 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
slot="prefix" slot="prefix"
/> />
<span slot="heading">${voiceAssistants[key].name}</span> <span slot="heading">${voiceAssistants[key].name}</span>
${key === "cloud.google_assistant" && ${!supported
!googleManual && ? html`<div slot="description">
this._googleEntity?.might_2fa ${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` ? html`
<ha-formfield <ha-formfield
slot="description" slot="description"
@ -193,30 +252,16 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
></ha-checkbox> ></ha-checkbox>
</ha-formfield> </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} : nothing}
<ha-switch <ha-switch
.assistant=${key} .assistant=${key}
@change=${this._toggleAssistant} @change=${this._toggleAssistant}
.disabled=${(alexaManual && key === "cloud.alexa") || .disabled=${manualConfig || (!exposed && !supported)}
(googleManual && key === "cloud.google_assistant")} .checked=${exposed}
.checked=${alexaManual && key === "cloud.alexa"
? manExposedAlexa
: googleManual && key === "cloud.google_assistant"
? manExposedGoogle
: this.entry.options?.[key]?.should_expose}
></ha-switch> ></ha-switch>
</ha-settings-row> </ha-settings-row>
` `;
) })
: nothing} : nothing}
<h3 class="header"> <h3 class="header">
@ -283,9 +328,15 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
} }
private async _toggleAll(ev) { private async _toggleAll(ev) {
const expose = ev.target.checked;
const assistants = expose
? ev.target.assistants.filter((key) => !this._unsupported[key])
: ev.target.assistants;
exposeEntities( exposeEntities(
this.hass, this.hass,
ev.target.assistants, assistants,
[this.entry.entity_id], [this.entry.entity_id],
ev.target.checked ev.target.checked
); );
@ -305,6 +356,7 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
margin: 32px; margin: 32px;
margin-top: 0; margin-top: 0;
--settings-row-prefix-display: contents; --settings-row-prefix-display: contents;
--settings-row-content-display: contents;
} }
ha-settings-row { ha-settings-row {
padding: 0; padding: 0;

View File

@ -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;
}
}

View File

@ -3,14 +3,21 @@ import "@lrnwebcomponents/simple-tooltip/simple-tooltip";
import { import {
mdiCloseBoxMultiple, mdiCloseBoxMultiple,
mdiCloseCircleOutline, mdiCloseCircleOutline,
mdiFilterVariant,
mdiPlus, mdiPlus,
mdiPlusBoxMultiple, mdiPlusBoxMultiple,
} from "@mdi/js"; } 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 { customElement, property, query, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map"; import { classMap } from "lit/directives/class-map";
import { ifDefined } from "lit/directives/if-defined"; import { ifDefined } from "lit/directives/if-defined";
import { styleMap } from "lit/directives/style-map";
import memoize from "memoize-one"; import memoize from "memoize-one";
import { HASSDomEvent } from "../../../common/dom/fire_event"; import { HASSDomEvent } from "../../../common/dom/fire_event";
import { import {
@ -27,6 +34,7 @@ import {
SelectionChangedEvent, SelectionChangedEvent,
} from "../../../components/data-table/ha-data-table"; } from "../../../components/data-table/ha-data-table";
import "../../../components/ha-fab"; import "../../../components/ha-fab";
import { AlexaEntity, fetchCloudAlexaEntities } from "../../../data/alexa";
import { CloudStatus, CloudStatusLoggedIn } from "../../../data/cloud"; import { CloudStatus, CloudStatusLoggedIn } from "../../../data/cloud";
import { entitiesContext } from "../../../data/context"; import { entitiesContext } from "../../../data/context";
import { import {
@ -35,6 +43,10 @@ import {
ExtEntityRegistryEntry, ExtEntityRegistryEntry,
getExtendedEntityRegistryEntries, getExtendedEntityRegistryEntries,
} from "../../../data/entity_registry"; } from "../../../data/entity_registry";
import {
fetchCloudGoogleEntities,
GoogleEntity,
} from "../../../data/google_assistant";
import { exposeEntities, voiceAssistants } from "../../../data/voice"; import { exposeEntities, voiceAssistants } from "../../../data/voice";
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box"; import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
import "../../../layouts/hass-loading-screen"; 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 type { HaTabsSubpageDataTable } from "../../../layouts/hass-tabs-subpage-data-table";
import { haStyle } from "../../../resources/styles"; import { haStyle } from "../../../resources/styles";
import { HomeAssistant, Route } from "../../../types"; import { HomeAssistant, Route } from "../../../types";
import { brandsUrl } from "../../../util/brands-url";
import { voiceAssistantTabs } from "./ha-config-voice-assistants"; import { voiceAssistantTabs } from "./ha-config-voice-assistants";
import { showExposeEntityDialog } from "./show-dialog-expose-entity"; import { showExposeEntityDialog } from "./show-dialog-expose-entity";
import { showVoiceSettingsDialog } from "./show-dialog-voice-settings"; import { showVoiceSettingsDialog } from "./show-dialog-voice-settings";
import "./expose/expose-assistant-icon";
@customElement("ha-config-voice-assistants-expose") @customElement("ha-config-voice-assistants-expose")
export class VoiceAssistantsExpose extends LitElement { export class VoiceAssistantsExpose extends LitElement {
@ -73,6 +85,11 @@ export class VoiceAssistantsExpose extends LitElement {
@state() private _selectedEntities: string[] = []; @state() private _selectedEntities: string[] = [];
@state() private _supportedEntities?: Record<
"cloud.google_assistant" | "cloud.alexa" | "conversation",
string[] | undefined
>;
@query("hass-tabs-subpage-data-table", true) @query("hass-tabs-subpage-data-table", true)
private _dataTable!: HaTabsSubpageDataTable; private _dataTable!: HaTabsSubpageDataTable;
@ -139,35 +156,23 @@ export class VoiceAssistantsExpose extends LitElement {
width: "160px", width: "160px",
type: "flex", type: "flex",
template: (assistants, entry) => template: (assistants, entry) =>
html`${availableAssistants.map((key) => html`${availableAssistants.map((key) => {
assistants.includes(key) const supported =
? html`<div> !this._supportedEntities?.[key] ||
<img this._supportedEntities[key].includes(entry.entity_id);
style="height: 24px; margin-right: 16px;${styleMap({ const manual = entry.manAssistants?.includes(key);
filter: entry.manAssistants?.includes(key) return assistants.includes(key)
? "grayscale(100%)" ? html`
: "", <voice-assistants-expose-assistant-icon
})}" .assistant=${key}
alt="" .hass=${this.hass}
src=${brandsUrl({ .manual=${manual}
domain: voiceAssistants[key].domain, .unsupported=${!supported}
type: "icon", >
darkOptimized: this.hass.themes?.darkMode, </voice-assistants-expose-assistant-icon>
})} `
referrerpolicy="no-referrer" : html`<div style="width: 40px;"></div>`;
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>`
)}`,
}, },
aliases: { aliases: {
title: this.hass.localize( title: this.hass.localize(
@ -197,6 +202,12 @@ export class VoiceAssistantsExpose extends LitElement {
.path=${mdiCloseCircleOutline} .path=${mdiCloseCircleOutline}
></ha-icon-button>`, ></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._extEntities = await getExtendedEntityRegistryEntries(
this.hass, this.hass,
Object.keys(this._entities) 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 { public willUpdate(changedProperties: PropertyValues): void {
if (changedProperties.has("_entities")) { 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-svg-icon slot="icon" .path=${mdiPlus}></ha-svg-icon>
</ha-fab> </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> </hass-tabs-subpage-data-table>
`; `;
} }

View File

@ -1083,7 +1083,8 @@
"aliases_header": "Aliases", "aliases_header": "Aliases",
"aliases_description": "Aliases are supported by Assist and Google Assistant.", "aliases_description": "Aliases are supported by Assist and Google Assistant.",
"ask_pin": "Ask for PIN", "ask_pin": "Ask for PIN",
"manual_config": "Managed with filters in configuration.yaml" "manual_config": "Managed in configuration.yaml",
"unsupported": "Unsupported"
}, },
"restart": { "restart": {
"heading": "Restart Home Assistant", "heading": "Restart Home Assistant",
@ -2039,6 +2040,8 @@
"add_assistant_title": "Add assistant", "add_assistant_title": "Add assistant",
"add_assistant_action": "Create", "add_assistant_action": "Create",
"try_tts": "Try voice", "try_tts": "Try voice",
"debug": "Debug",
"set_as_preferred": "Set as preferred",
"form": { "form": {
"name": "Name", "name": "Name",
"conversation_engine": "Conversation agent", "conversation_engine": "Conversation agent",
@ -2105,6 +2108,8 @@
"expose_confirm_text": "Do you want to expose {entities} entities to {assistants}?", "expose_confirm_text": "Do you want to expose {entities} entities to {assistants}?",
"unexpose_confirm_title": "Stop exposing selected entities?", "unexpose_confirm_title": "Stop exposing selected entities?",
"unexpose_confirm_text": "Do you want to stop exposing {entities} entities to {assistants}?", "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": { "expose_dialog": {
"header": "Expose entities", "header": "Expose entities",
"expose_to": "to {assistants}", "expose_to": "to {assistants}",

View File

@ -16585,9 +16585,9 @@ __metadata:
linkType: hard linkType: hard
"yaml@npm:^2.2.1": "yaml@npm:^2.2.1":
version: 2.2.1 version: 2.2.2
resolution: "yaml@npm:2.2.1" resolution: "yaml@npm:2.2.2"
checksum: 84f68cbe462d5da4e7ded4a8bded949ffa912bc264472e5a684c3d45b22d8f73a3019963a32164023bdf3d83cfb6f5b58ff7b2b10ef5b717c630f40bd6369a23 checksum: d90c235e099e30094dcff61ba3350437aef53325db4a6bcd04ca96e1bfe7e348b191f6a7a52b5211e2dbc4eeedb22a00b291527da030de7c189728ef3f2b4eb3
languageName: node languageName: node
linkType: hard linkType: hard