Minor main card tidyup.
This commit is contained in:
+22
-29
@@ -88,20 +88,6 @@ function shouldUpdateBasedOnHass(
|
|||||||
// Main FrigateCard class.
|
// Main FrigateCard class.
|
||||||
@customElement('frigate-card')
|
@customElement('frigate-card')
|
||||||
export class FrigateCard extends LitElement {
|
export class FrigateCard extends LitElement {
|
||||||
// Get the configuration element.
|
|
||||||
public static async getConfigElement(): Promise<LovelaceCardEditor> {
|
|
||||||
return document.createElement('frigate-card-editor');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a stub basic config.
|
|
||||||
public static getStubConfig(): Record<string, string> {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
set hass(hass: HomeAssistant & ExtendedHomeAssistant) {
|
|
||||||
this._hass = hass;
|
|
||||||
this._updateMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
protected _hass: (HomeAssistant & ExtendedHomeAssistant) | null = null;
|
protected _hass: (HomeAssistant & ExtendedHomeAssistant) | null = null;
|
||||||
|
|
||||||
@@ -113,16 +99,31 @@ export class FrigateCard extends LitElement {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
protected _view: View = new View();
|
protected _view: View = new View();
|
||||||
|
|
||||||
|
@query('frigate-card-menu')
|
||||||
|
_menu!: FrigateCardMenu;
|
||||||
|
|
||||||
// Whether or not there is an active clip being played.
|
// Whether or not there is an active clip being played.
|
||||||
protected _clipPlaying = false;
|
protected _clipPlaying = false;
|
||||||
|
|
||||||
@query('frigate-card-menu')
|
|
||||||
_menu!: FrigateCardMenu | null;
|
|
||||||
|
|
||||||
// A small cache to avoid needing to create a new list of entities every time
|
// A small cache to avoid needing to create a new list of entities every time
|
||||||
// a hass update arrives.
|
// a hass update arrives.
|
||||||
protected _entitiesToMonitor: string[] | null = null;
|
protected _entitiesToMonitor: string[] | null = null;
|
||||||
|
|
||||||
|
set hass(hass: HomeAssistant & ExtendedHomeAssistant) {
|
||||||
|
this._hass = hass;
|
||||||
|
this._updateMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the configuration element.
|
||||||
|
public static async getConfigElement(): Promise<LovelaceCardEditor> {
|
||||||
|
return document.createElement('frigate-card-editor');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a stub basic config.
|
||||||
|
public static getStubConfig(): Record<string, string> {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
protected _updateMenu(): void {
|
protected _updateMenu(): void {
|
||||||
// Manually set hass in the menu. This is to allow the menu to update,
|
// Manually set hass in the menu. This is to allow the menu to update,
|
||||||
// without necessarily re-rendering the entire card (re-rendering interrupts
|
// without necessarily re-rendering the entire card (re-rendering interrupts
|
||||||
@@ -130,7 +131,6 @@ export class FrigateCard extends LitElement {
|
|||||||
if (!this._menu || !this._hass) {
|
if (!this._menu || !this._hass) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._menu.buttons = this._getMenuButtons();
|
this._menu.buttons = this._getMenuButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,17 +217,6 @@ export class FrigateCard extends LitElement {
|
|||||||
this._changeView();
|
this._changeView();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _changeViewHandler(e: CustomEvent<View>): void {
|
|
||||||
const view = e.detail;
|
|
||||||
|
|
||||||
if (view === undefined) {
|
|
||||||
this._view = new View({ view: this.config.view_default });
|
|
||||||
} else {
|
|
||||||
this._view = view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the card view.
|
|
||||||
protected _changeView(view?: View | undefined): void {
|
protected _changeView(view?: View | undefined): void {
|
||||||
if (view === undefined) {
|
if (view === undefined) {
|
||||||
this._view = new View({ view: this.config.view_default });
|
this._view = new View({ view: this.config.view_default });
|
||||||
@@ -236,6 +225,10 @@ export class FrigateCard extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected _changeViewHandler(e: CustomEvent<View>): void {
|
||||||
|
this._changeView(e.detail);
|
||||||
|
}
|
||||||
|
|
||||||
// Determine whether the card should be updated.
|
// Determine whether the card should be updated.
|
||||||
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
||||||
if (!this.config) {
|
if (!this.config) {
|
||||||
|
|||||||
Reference in New Issue
Block a user