Initial update force work.

This commit is contained in:
Dermot Duffy
2021-11-28 15:45:40 -08:00
parent 4315f6960e
commit df703c7293
6 changed files with 64 additions and 19 deletions
+14 -2
View File
@@ -507,6 +507,10 @@ export class FrigateCard extends LitElement {
if (this.config.camera_entity) {
this._entitiesToMonitor.push(this.config.camera_entity);
}
if (this.config.view.update_force) {
// If update force is enabled, start a timer right away.
this._resetInteractionTimer();
}
this._changeView();
}
@@ -538,7 +542,8 @@ export class FrigateCard extends LitElement {
if (!this.config) {
return false;
}
if (changedProps.has('config')) {
if (changedProps.size > 1) {
return true;
}
@@ -550,7 +555,7 @@ export class FrigateCard extends LitElement {
// are browsing the mini-gallery). Do not allow re-rendering from a Home
// Assistant update if there's been recent interaction (e.g. clicks on the
// card) or if there is media active playing.
if (this._interactionTimerID || this._mediaPlaying) {
if (!this.config.view.update_force && (this._interactionTimerID || this._mediaPlaying)) {
return false;
}
return shouldUpdateBasedOnHass(this._hass, oldHass, this._entitiesToMonitor);
@@ -709,7 +714,10 @@ export class FrigateCard extends LitElement {
) {
handleAction(node, this._hass as HomeAssistant, config, ev.detail.action);
}
this._resetInteractionTimer();
}
protected _resetInteractionTimer(): void {
if (this.config.view.timeout) {
if (this._interactionTimerID) {
window.clearTimeout(this._interactionTimerID);
@@ -717,6 +725,10 @@ export class FrigateCard extends LitElement {
this._interactionTimerID = window.setTimeout(() => {
this._interactionTimerID = null;
this._changeView();
if (this.config.view.update_force) {
// If force is enabled, the timer just resets and starts over.
this._resetInteractionTimer();
}
}, this.config.view.timeout * 1000);
}
}
+1
View File
@@ -11,6 +11,7 @@ export const CONF_FRIGATE_ZONE = 'frigate.zone';
export const CONF_VIEW_DEFAULT = 'view.default';
export const CONF_VIEW_TIMEOUT = 'view.timeout';
export const CONF_VIEW_UPDATE_FORCE = 'view.update_force';
export const CONF_EVENT_VIEWER_AUTOPLAY_CLIP = 'event_viewer.autoplay_clip';
export const CONF_EVENT_VIEWER_DRAGGABLE = 'event_viewer.draggable';
+4
View File
@@ -53,6 +53,7 @@ import {
CONF_MENU_MODE,
CONF_VIEW_DEFAULT,
CONF_VIEW_TIMEOUT,
CONF_VIEW_UPDATE_FORCE,
} from './const.js';
interface EditorOptionsSet {
@@ -403,6 +404,9 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
<div class="values">
${this._renderDropdown(CONF_VIEW_DEFAULT, viewModes)}
${this._renderStringInput(CONF_VIEW_TIMEOUT, '[0-9]')}
${this._renderSwitch(
CONF_VIEW_UPDATE_FORCE,
defaults.view.update_force)}
</div>
`
: ''}
+2 -1
View File
@@ -27,7 +27,8 @@
"snapshots": "Snapshots gallery",
"image": "Static image"
},
"timeout": "View timeout secs (before returning to default, 0=never)"
"timeout": "View timeout secs (before returning to default, 0=never)",
"update_force": "Force card updates (ignore media playing / interaction)"
},
"event_viewer": {
"autoplay_clip": "Autoplay most recent clip (In 'clip' view)",
+2
View File
@@ -323,6 +323,7 @@ const frigateConfigDefaultSchema = z
const viewConfigDefault = {
default: 'live' as const,
timeout: 180,
update_force: false,
};
const viewConfigSchema = z
.object({
@@ -340,6 +341,7 @@ const viewConfigSchema = z
)
.optional()
.default(viewConfigDefault.timeout),
update_force: z.boolean().default(viewConfigDefault.update_force),
})
.merge(actionsSchema)
.default(viewConfigDefault);