Fetch supported items when startup is done (#16390)

This commit is contained in:
Bram Kragten 2023-05-03 12:36:16 +02:00 committed by GitHub
parent a3ec83a684
commit b550c67a9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -119,7 +119,17 @@ export class VoiceAssistantsExpose extends LitElement {
); );
private _columns = memoize( private _columns = memoize(
(narrow, availableAssistants, _language): DataTableColumnContainer => ({ (
narrow: boolean,
availableAssistants: string[],
supportedEntities:
| Record<
"cloud.google_assistant" | "cloud.alexa" | "conversation",
string[] | undefined
>
| undefined,
_language: string
): DataTableColumnContainer => ({
icon: { icon: {
title: "", title: "",
type: "icon", type: "icon",
@ -166,8 +176,8 @@ export class VoiceAssistantsExpose extends LitElement {
template: (assistants, entry) => template: (assistants, entry) =>
html`${availableAssistants.map((key) => { html`${availableAssistants.map((key) => {
const supported = const supported =
!this._supportedEntities?.[key] || !supportedEntities?.[key] ||
this._supportedEntities[key].includes(entry.entity_id); supportedEntities[key].includes(entry.entity_id);
const manual = entry.manAssistants?.includes(key); const manual = entry.manAssistants?.includes(key);
return assistants.includes(key) return assistants.includes(key)
? html` ? html`
@ -450,6 +460,10 @@ export class VoiceAssistantsExpose extends LitElement {
this.hass, this.hass,
Object.keys(this._entities) Object.keys(this._entities)
); );
this._fetchSupportedEntities();
}
private async _fetchSupportedEntities() {
let alexaEntitiesProm: Promise<AlexaEntity[]> | undefined; let alexaEntitiesProm: Promise<AlexaEntity[]> | undefined;
let googleEntitiesProm: Promise<GoogleEntity[]> | undefined; let googleEntitiesProm: Promise<GoogleEntity[]> | undefined;
if (this.cloudStatus?.logged_in && this.cloudStatus.prefs.alexa_enabled) { if (this.cloudStatus?.logged_in && this.cloudStatus.prefs.alexa_enabled) {
@ -467,7 +481,7 @@ export class VoiceAssistantsExpose extends LitElement {
"cloud.google_assistant": googleEntities?.map( "cloud.google_assistant": googleEntities?.map(
(entity) => entity.entity_id (entity) => entity.entity_id
), ),
// TODO add supported entity for assit // TODO add supported entity for assist
conversation: undefined, conversation: undefined,
}; };
} }
@ -475,6 +489,14 @@ export class VoiceAssistantsExpose extends LitElement {
public willUpdate(changedProperties: PropertyValues): void { public willUpdate(changedProperties: PropertyValues): void {
if (changedProperties.has("_entities")) { if (changedProperties.has("_entities")) {
this._fetchEntities(); this._fetchEntities();
return;
}
if (
changedProperties.has("hass") &&
this.hass.config.state === "RUNNING" &&
changedProperties.get("hass")?.config.state !== this.hass.config.state
) {
this._fetchSupportedEntities();
} }
} }
@ -505,6 +527,7 @@ export class VoiceAssistantsExpose extends LitElement {
.columns=${this._columns( .columns=${this._columns(
this.narrow, this.narrow,
this._availableAssistants(this.cloudStatus), this._availableAssistants(this.cloudStatus),
this._supportedEntities,
this.hass.language this.hass.language
)} )}
.data=${filteredEntities} .data=${filteredEntities}