Better integrate elements into stock HA custom element support.

This commit is contained in:
Dermot Duffy
2021-10-09 15:52:52 -07:00
parent 49455ab741
commit 9a915af390
7 changed files with 201 additions and 80 deletions
+13 -10
View File
@@ -19,7 +19,11 @@ import {
} from 'custom-card-helpers';
import screenfull from 'screenfull';
import { entitySchema, frigateCardConfigSchema, Message } from './types';
import {
entitySchema,
frigateCardConfigSchema,
Message,
} from './types';
import type {
BrowseMediaQueryParameters,
Entity,
@@ -204,14 +208,6 @@ export class FrigateCard extends LitElement {
icon: screenfull.isFullscreen ? 'mdi:fullscreen-exit' : 'mdi:fullscreen',
});
}
const elements = this.config.elements || [];
for (let i = 0; this._hass && i < elements.length; i++) {
const element = elements[i];
if (element.type == 'menu-icon' || element.type == 'menu-state-icon') {
buttons.push(element);
}
}
return buttons;
}
@@ -573,7 +569,7 @@ export class FrigateCard extends LitElement {
this._frigateCameraName = await this._getFrigateCameraName();
}
const mediaQueryParameters = this._getBrowseMediaQueryParameters();
if (!this._frigateCameraName || !mediaQueryParameters) {
if (!this._hass || !this._frigateCameraName || !mediaQueryParameters) {
return this._setMessageAndUpdate({
message: localize('error.no_frigate_camera_name'),
type: 'error',
@@ -629,6 +625,13 @@ export class FrigateCard extends LitElement {
<frigate-card-elements
.hass=${this._hass}
.pictureElements=${this.config.elements}
@frigate-card:message=${this._messageHandler}
@frigate-card:menu-add=${(e) => {
this._menu.addButton(e.detail);
}}
@frigate-card:menu-remove=${(e) => {
this._menu.removeButton(e.detail);
}}
>
</frigate-card-elements>
</div>