Fix render bug.
This commit is contained in:
+54
-26
@@ -87,12 +87,14 @@ function shouldUpdateBasedOnHass(
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A menu for the Frigate card.
|
// A menu for the Frigate card.
|
||||||
@customElement('frigate-card-menu')
|
@customElement('frigate-card-menu')
|
||||||
export class FrigateCardMenu extends LitElement {
|
export class FrigateCardMenu extends LitElement {
|
||||||
|
static FRIGATE_CARD_MENU_ID: string = 'frigate-card-menu-id' as const;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
protected expand = false;
|
protected expand = false;
|
||||||
|
|
||||||
@@ -100,7 +102,7 @@ export class FrigateCardMenu extends LitElement {
|
|||||||
protected motionEntity: string | null = null;
|
protected motionEntity: string | null = null;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
protected hass: HomeAssistant | null = null;
|
public hass: HomeAssistant | null = null;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
protected actionCallback: FrigateCardMenuCallback | null = null;
|
protected actionCallback: FrigateCardMenuCallback | null = null;
|
||||||
@@ -109,11 +111,11 @@ export class FrigateCardMenu extends LitElement {
|
|||||||
protected heading: string | null = null;
|
protected heading: string | null = null;
|
||||||
|
|
||||||
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
||||||
return shouldUpdateBasedOnHass(
|
const oldHass = changedProps.get('hass') as HomeAssistant | undefined;
|
||||||
this.hass,
|
if (oldHass) {
|
||||||
changedProps.get('hass') as HomeAssistant | undefined,
|
return shouldUpdateBasedOnHass(this.hass, oldHass, [this.motionEntity]);
|
||||||
[this.motionEntity],
|
}
|
||||||
);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the Frigate menu button.
|
// Render the Frigate menu button.
|
||||||
@@ -237,6 +239,16 @@ export class FrigateCard extends LitElement {
|
|||||||
this._webrtcElement.hass = hass;
|
this._webrtcElement.hass = hass;
|
||||||
}
|
}
|
||||||
this._hass = hass;
|
this._hass = hass;
|
||||||
|
|
||||||
|
// Manually set hass in the menu. This is to allow the menu to update,
|
||||||
|
// without necessarily re-rendering the entire card (re-rendering interrupts
|
||||||
|
// clip playing).
|
||||||
|
const menu = this.shadowRoot?.getElementById(
|
||||||
|
FrigateCardMenu.FRIGATE_CARD_MENU_ID,
|
||||||
|
) as FrigateCardMenu;
|
||||||
|
if (menu) {
|
||||||
|
menu.hass = hass;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
@@ -260,6 +272,9 @@ export class FrigateCard extends LitElement {
|
|||||||
protected _interactionTimerID: number | null = null;
|
protected _interactionTimerID: number | null = null;
|
||||||
protected _webrtcElement: any | null = null;
|
protected _webrtcElement: any | null = null;
|
||||||
|
|
||||||
|
// Whether or not there is an active clip being played.
|
||||||
|
protected _clipPlaying = false;
|
||||||
|
|
||||||
// Set the object configuration.
|
// Set the object configuration.
|
||||||
public setConfig(inputConfig: FrigateCardConfig): void {
|
public setConfig(inputConfig: FrigateCardConfig): void {
|
||||||
if (!inputConfig) {
|
if (!inputConfig) {
|
||||||
@@ -321,11 +336,19 @@ export class FrigateCard extends LitElement {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return shouldUpdateBasedOnHass(
|
const oldHass = changedProps.get('_hass') as HomeAssistant | undefined;
|
||||||
this._hass,
|
if (oldHass) {
|
||||||
changedProps.get('_hass') as HomeAssistant | undefined,
|
// A re-render will interrupt a clip that is playing. Do not allow this
|
||||||
[this.config.camera_entity, this.config.motion_entity],
|
// for hass state updates.
|
||||||
);
|
if (this._clipPlaying) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return shouldUpdateBasedOnHass(this._hass, oldHass, [
|
||||||
|
this.config.camera_entity,
|
||||||
|
this.config.motion_entity,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get FrigateEvents from the Frigate server API.
|
// Get FrigateEvents from the Frigate server API.
|
||||||
@@ -441,7 +464,7 @@ export class FrigateCard extends LitElement {
|
|||||||
this._viewEvent = event;
|
this._viewEvent = event;
|
||||||
this._viewMode = want_clips ? 'clip' : 'snapshot';
|
this._viewMode = want_clips ? 'clip' : 'snapshot';
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</li>`,
|
</li>`,
|
||||||
)}
|
)}
|
||||||
@@ -554,7 +577,6 @@ export class FrigateCard extends LitElement {
|
|||||||
return `${this.config.frigate_url}/clips/${event.camera}-${event.id}.jpg`;
|
return `${this.config.frigate_url}/clips/${event.camera}-${event.id}.jpg`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Render the player for a saved clip.
|
// Render the player for a saved clip.
|
||||||
protected async _renderClipPlayer(): Promise<TemplateResult> {
|
protected async _renderClipPlayer(): Promise<TemplateResult> {
|
||||||
let event: FrigateEvent, events: FrigateGetEventsResponse;
|
let event: FrigateEvent, events: FrigateGetEventsResponse;
|
||||||
@@ -596,9 +618,15 @@ export class FrigateCard extends LitElement {
|
|||||||
class="frigate-card-viewer"
|
class="frigate-card-viewer"
|
||||||
muted
|
muted
|
||||||
controls
|
controls
|
||||||
|
@play=${() => {
|
||||||
|
this._clipPlaying = true;
|
||||||
|
}}
|
||||||
|
@pause=${() => {
|
||||||
|
this._clipPlaying = false;
|
||||||
|
}}
|
||||||
?autoplay="${autoplay}"
|
?autoplay="${autoplay}"
|
||||||
>
|
>
|
||||||
<source src="${clipURL}" type="video/mp4">
|
<source src="${clipURL}" type="video/mp4" />
|
||||||
</video>`;
|
</video>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,17 +659,16 @@ export class FrigateCard extends LitElement {
|
|||||||
|
|
||||||
this._heading = this._getEventTitle(event);
|
this._heading = this._getEventTitle(event);
|
||||||
|
|
||||||
return html`
|
return html` <img
|
||||||
<img
|
class="frigate-card-viewer"
|
||||||
class="frigate-card-viewer"
|
src="${snapshotURL}"
|
||||||
src="${snapshotURL}"
|
@click=${() => {
|
||||||
@click=${() => {
|
if (event.has_clip) {
|
||||||
if (event.has_clip) {
|
this._viewEvent = event;
|
||||||
this._viewEvent = event;
|
this._viewMode = 'clip';
|
||||||
this._viewMode = 'clip';
|
}
|
||||||
}
|
}}
|
||||||
}}
|
/>`;
|
||||||
>`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the live viewer.
|
// Render the live viewer.
|
||||||
@@ -722,6 +749,7 @@ export class FrigateCard extends LitElement {
|
|||||||
}
|
}
|
||||||
${this._renderLiveViewer()}
|
${this._renderLiveViewer()}
|
||||||
<frigate-card-menu
|
<frigate-card-menu
|
||||||
|
id="${FrigateCardMenu.FRIGATE_CARD_MENU_ID}"
|
||||||
.motionEntity=${this.config.motion_entity}
|
.motionEntity=${this.config.motion_entity}
|
||||||
.hass=${this._hass}
|
.hass=${this._hass}
|
||||||
.actionCallback=${this._menuActionHandler.bind(this)}
|
.actionCallback=${this._menuActionHandler.bind(this)}
|
||||||
|
|||||||
Reference in New Issue
Block a user