Don't fetch thumbnails on preloaded background cameras.

This commit is contained in:
Dermot Duffy
2022-05-09 09:43:05 -07:00
parent 470f8fa1c1
commit e5a9eb1392
3 changed files with 17 additions and 11 deletions
+6 -2
View File
@@ -139,14 +139,18 @@ export class FrigateCardLive extends LitElement {
return; return;
} }
// Note use of liveConfig and not config below -- the carousel will // Notes:
// independently override the liveconfig to reflect the camera in the // - See use of liveConfig and not config below -- the carousel will
// independently override the liveConfig to reflect the camera in the
// carousel (not necessarily the selected camera). // carousel (not necessarily the selected camera).
// - Fetching of thumbnails is disabled as long as live view is the
// background (preloaded) rather than foreground (not preloaded).
return html` <frigate-card-surround-thumbnails return html` <frigate-card-surround-thumbnails
.hass=${this.hass} .hass=${this.hass}
.view=${this.view} .view=${this.view}
.config=${config.controls.thumbnails} .config=${config.controls.thumbnails}
.browseMediaParams=${browseMediaParams} .browseMediaParams=${browseMediaParams}
?fetch=${!this._preloaded}
> >
<frigate-card-live-carousel <frigate-card-live-carousel
.hass=${this.hass} .hass=${this.hass}
+9 -7
View File
@@ -33,16 +33,18 @@ export class FrigateCardSurround extends LitElement {
@property({ attribute: false }) @property({ attribute: false })
protected targetView?: FrigateCardView; protected targetView?: FrigateCardView;
@property({ attribute: true, type: Boolean })
protected fetch?: boolean;
@property({ attribute: false }) @property({ attribute: false })
protected browseMediaParams?: protected browseMediaParams?:
| BrowseMediaQueryParameters | BrowseMediaQueryParameters
| BrowseMediaQueryParameters[]; | BrowseMediaQueryParameters[];
// A task to await the load of the WebRTC component.
protected _browseTask = new Task(this, this._fetchMedia.bind(this), () => [ protected _browseTask = new Task(this, this._fetchMedia.bind(this), () => [
this.hass,
this.view, this.view,
this.browseMediaParams, this.browseMediaParams,
this.fetch,
]); ]);
/** /**
@@ -51,25 +53,25 @@ export class FrigateCardSurround extends LitElement {
* @param param Task parameters. * @param param Task parameters.
* @returns * @returns
*/ */
protected async _fetchMedia([hass, view, browseMediaParams]: ( protected async _fetchMedia([view, browseMediaParams, fetch]: (
| HomeAssistant
| Readonly<View> | Readonly<View>
| BrowseMediaQueryParameters | BrowseMediaQueryParameters
| BrowseMediaQueryParameters[] | BrowseMediaQueryParameters[]
| boolean
| undefined | undefined
)[]): Promise<void> { )[]): Promise<void> {
hass = hass as HomeAssistant;
view = view as Readonly<View>; view = view as Readonly<View>;
browseMediaParams = browseMediaParams as browseMediaParams = browseMediaParams as
| BrowseMediaQueryParameters | BrowseMediaQueryParameters
| BrowseMediaQueryParameters[]; | BrowseMediaQueryParameters[];
fetch = fetch as boolean;
if (!hass || !view || view.target || !browseMediaParams) { if (!fetch || !this.hass || !view || view.target || !browseMediaParams) {
return; return;
} }
let parent: FrigateBrowseMediaSource | null; let parent: FrigateBrowseMediaSource | null;
try { try {
parent = await BrowseMediaUtil.multipleBrowseMediaQueryMerged(hass, browseMediaParams); parent = await BrowseMediaUtil.multipleBrowseMediaQueryMerged(this.hass, browseMediaParams);
} catch (e) { } catch (e) {
return dispatchErrorMessageEvent(this, (e as Error).message); return dispatchErrorMessageEvent(this, (e as Error).message);
} }
+1 -1
View File
@@ -177,9 +177,9 @@ const noActionSchema = schemaForType<
); );
const frigateCardCustomactionsBaseSchema = customActionSchema.extend({ const frigateCardCustomactionsBaseSchema = customActionSchema.extend({
// Syntactic sugar to avoid 'fire-dom-event' as part of an external API.
action: z action: z
.literal('custom:frigate-card-action') .literal('custom:frigate-card-action')
// Syntactic sugar to avoid 'fire-dom-event' as part of an external API.
.transform((): 'fire-dom-event' => 'fire-dom-event') .transform((): 'fire-dom-event' => 'fire-dom-event')
.or(z.literal('fire-dom-event')), .or(z.literal('fire-dom-event')),
}); });