Refactor to avoid use of "all-static" classes.
This commit is contained in:
@@ -13,7 +13,11 @@ import { customElement, property } from 'lit/decorators.js';
|
||||
import galleryStyle from '../scss/gallery.scss';
|
||||
import { CameraConfig, frigateCardConfigDefaults, GalleryConfig } from '../types.js';
|
||||
import { stopEventFromActivatingCardWideActions } from '../utils/action.js';
|
||||
import { BrowseMediaUtil } from '../utils/ha/browse-media.js';
|
||||
import {
|
||||
fetchChildMediaAndDispatchViewChange,
|
||||
fetchLatestMediaAndDispatchViewChange,
|
||||
getFullDependentBrowseMediaQueryParametersOrDispatchError
|
||||
} from '../utils/ha/browse-media';
|
||||
import { View } from '../view.js';
|
||||
import { renderProgressIndicator } from './message.js';
|
||||
import './thumbnail.js';
|
||||
@@ -51,7 +55,7 @@ export class FrigateCardGallery extends LitElement {
|
||||
|
||||
if (!this.view.target) {
|
||||
const browseMediaQueryParameters =
|
||||
BrowseMediaUtil.getFullDependentBrowseMediaQueryParametersOrDispatchError(
|
||||
getFullDependentBrowseMediaQueryParametersOrDispatchError(
|
||||
this,
|
||||
this.hass,
|
||||
this.cameras,
|
||||
@@ -63,7 +67,7 @@ export class FrigateCardGallery extends LitElement {
|
||||
return;
|
||||
}
|
||||
|
||||
BrowseMediaUtil.fetchLatestMediaAndDispatchViewChange(
|
||||
fetchLatestMediaAndDispatchViewChange(
|
||||
this,
|
||||
this.hass,
|
||||
this.view,
|
||||
@@ -216,7 +220,7 @@ export class FrigateCardGalleryCore extends LitElement {
|
||||
<ha-card
|
||||
@click=${(ev) => {
|
||||
if (this.hass && this.view) {
|
||||
BrowseMediaUtil.fetchChildMediaAndDispatchViewChange(
|
||||
fetchChildMediaAndDispatchViewChange(
|
||||
this,
|
||||
this.hass,
|
||||
this.view,
|
||||
|
||||
@@ -38,7 +38,7 @@ import { stopEventFromActivatingCardWideActions } from '../utils/action.js';
|
||||
import { contentsChanged } from '../utils/basic.js';
|
||||
import { getCameraIcon, getCameraTitle } from '../utils/camera.js';
|
||||
import { homeAssistantSignPath } from '../utils/ha';
|
||||
import { BrowseMediaUtil } from '../utils/ha/browse-media.js';
|
||||
import { getFullDependentBrowseMediaQueryParameters } from '../utils/ha/browse-media.js';
|
||||
import {
|
||||
dispatchExistingMediaShowInfoAsEvent,
|
||||
dispatchMediaShowEvent
|
||||
@@ -125,7 +125,7 @@ export class FrigateCardLive extends LitElement {
|
||||
// Does not use getFullDependentBrowseMediaQueryParametersOrDispatchError to
|
||||
// ensure that non-Frigate cameras will work in live view (they will not
|
||||
// have a Frigate camera name).
|
||||
const browseMediaParams = BrowseMediaUtil.getFullDependentBrowseMediaQueryParameters(
|
||||
const browseMediaParams = getFullDependentBrowseMediaQueryParameters(
|
||||
this.hass,
|
||||
this.cameras,
|
||||
this.view.camera,
|
||||
|
||||
@@ -10,7 +10,10 @@ import {
|
||||
ThumbnailsControlConfig
|
||||
} from '../types.js';
|
||||
import { dispatchFrigateCardEvent } from '../utils/basic.js';
|
||||
import { BrowseMediaUtil } from '../utils/ha/browse-media.js';
|
||||
import {
|
||||
getFirstTrueMediaChildIndex,
|
||||
multipleBrowseMediaQueryMerged
|
||||
} from '../utils/ha/browse-media';
|
||||
import { View } from '../view.js';
|
||||
import { dispatchErrorMessageEvent } from './message.js';
|
||||
import './surround.js';
|
||||
@@ -68,14 +71,11 @@ export class FrigateCardSurround extends LitElement {
|
||||
}
|
||||
let parent: FrigateBrowseMediaSource | null;
|
||||
try {
|
||||
parent = await BrowseMediaUtil.multipleBrowseMediaQueryMerged(
|
||||
this.hass,
|
||||
browseMediaParams,
|
||||
);
|
||||
parent = await multipleBrowseMediaQueryMerged(this.hass, browseMediaParams);
|
||||
} catch (e) {
|
||||
return dispatchErrorMessageEvent(this, (e as Error).message);
|
||||
}
|
||||
if (BrowseMediaUtil.getFirstTrueMediaChildIndex(parent) !== null) {
|
||||
if (getFirstTrueMediaChildIndex(parent) !== null) {
|
||||
this.view
|
||||
?.evolve({
|
||||
...(this.targetView && { view: this.targetView }),
|
||||
|
||||
@@ -7,7 +7,7 @@ import thumbnailCarouselStyle from '../scss/thumbnail-carousel.scss';
|
||||
import type { FrigateBrowseMediaSource, ThumbnailsControlConfig } from '../types.js';
|
||||
import { stopEventFromActivatingCardWideActions } from '../utils/action.js';
|
||||
import { contentsChanged, dispatchFrigateCardEvent } from '../utils/basic.js';
|
||||
import { BrowseMediaUtil } from '../utils/ha/browse-media.js';
|
||||
import { isTrueMedia } from '../utils/ha/browse-media';
|
||||
import { View } from '../view.js';
|
||||
import { FrigateCardCarousel } from './carousel.js';
|
||||
import './thumbnail.js';
|
||||
@@ -154,7 +154,7 @@ export class FrigateCardThumbnailCarousel extends FrigateCardCarousel {
|
||||
if (
|
||||
!parent.children ||
|
||||
!parent.children.length ||
|
||||
!BrowseMediaUtil.isTrueMedia(parent.children[childIndex])
|
||||
!isTrueMedia(parent.children[childIndex])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
+18
-21
@@ -37,7 +37,12 @@ import {
|
||||
import { stopEventFromActivatingCardWideActions } from '../utils/action.js';
|
||||
import { dispatchFrigateCardEvent } from '../utils/basic.js';
|
||||
import { getCameraTitle } from '../utils/camera.js';
|
||||
import { BrowseMediaUtil } from '../utils/ha/browse-media.js';
|
||||
import {
|
||||
createEventParentForChildren,
|
||||
getBrowseMediaQueryParameters,
|
||||
isTrueMedia,
|
||||
multipleBrowseMediaQuery
|
||||
} from '../utils/ha/browse-media';
|
||||
import { View, ViewContext } from '../view';
|
||||
import { dispatchErrorMessageEvent, dispatchMessageEvent } from './message.js';
|
||||
import './surround-thumbnails.js';
|
||||
@@ -137,7 +142,7 @@ class TimelineEventManager {
|
||||
const event = child.frigate?.event;
|
||||
if (
|
||||
event &&
|
||||
BrowseMediaUtil.isTrueMedia(child) &&
|
||||
isTrueMedia(child) &&
|
||||
['video', 'image'].includes(child.media_content_type)
|
||||
) {
|
||||
let item = this._dataset.get(event.id);
|
||||
@@ -282,20 +287,15 @@ class TimelineEventManager {
|
||||
this._dateStart &&
|
||||
cameraConfig.camera_name !== CAMERA_BIRDSEYE
|
||||
) {
|
||||
const param = BrowseMediaUtil.getBrowseMediaQueryParameters(
|
||||
hass,
|
||||
cameraID,
|
||||
cameraConfig,
|
||||
{
|
||||
// Events are always fetched for the maximum extent of the managed
|
||||
// range. This is because events may change at any point in time
|
||||
// (e.g. a long-running event that ends).
|
||||
before: this._dateEnd.getTime() / 1000,
|
||||
after: this._dateStart.getTime() / 1000,
|
||||
unlimited: true,
|
||||
mediaType: mediaType as 'clips' | 'snapshots',
|
||||
},
|
||||
);
|
||||
const param = getBrowseMediaQueryParameters(hass, cameraID, cameraConfig, {
|
||||
// Events are always fetched for the maximum extent of the managed
|
||||
// range. This is because events may change at any point in time
|
||||
// (e.g. a long-running event that ends).
|
||||
before: this._dateEnd.getTime() / 1000,
|
||||
after: this._dateStart.getTime() / 1000,
|
||||
unlimited: true,
|
||||
mediaType: mediaType as 'clips' | 'snapshots',
|
||||
});
|
||||
if (param) {
|
||||
params.push(param);
|
||||
}
|
||||
@@ -309,7 +309,7 @@ class TimelineEventManager {
|
||||
|
||||
let results: Map<BrowseMediaQueryParameters, FrigateBrowseMediaSource>;
|
||||
try {
|
||||
results = await BrowseMediaUtil.multipleBrowseMediaQuery(hass, params);
|
||||
results = await multipleBrowseMediaQuery(hass, params);
|
||||
} catch (e) {
|
||||
return dispatchErrorMessageEvent(element, (e as Error).message);
|
||||
}
|
||||
@@ -572,10 +572,7 @@ export class FrigateCardTimelineCore extends LitElement {
|
||||
return null;
|
||||
}
|
||||
|
||||
const target = BrowseMediaUtil.createEventParentForChildren(
|
||||
'Timeline events',
|
||||
children,
|
||||
);
|
||||
const target = createEventParentForChildren('Timeline events', children);
|
||||
return {
|
||||
target: target,
|
||||
childIndex: childIndex < 0 ? null : childIndex,
|
||||
|
||||
+28
-22
@@ -28,9 +28,16 @@ import type {
|
||||
} from '../types.js';
|
||||
import { stopEventFromActivatingCardWideActions } from '../utils/action.js';
|
||||
import { contentsChanged } from '../utils/basic.js';
|
||||
import { BrowseMediaUtil } from '../utils/ha/browse-media.js';
|
||||
import {
|
||||
fetchLatestMediaAndDispatchViewChange,
|
||||
getEventStartTime,
|
||||
getFullDependentBrowseMediaQueryParametersOrDispatchError,
|
||||
isTrueMedia,
|
||||
multipleBrowseMediaQueryMerged,
|
||||
overrideMultiBrowseMediaQueryParameters
|
||||
} from '../utils/ha/browse-media.js';
|
||||
import { createMediaShowInfo } from '../utils/media-info.js';
|
||||
import { ResolvedMediaCache, ResolvedMediaUtil } from '../utils/resolved-media.js';
|
||||
import { ResolvedMediaCache, resolveMedia } from '../utils/resolved-media.js';
|
||||
import { View } from '../view.js';
|
||||
import { AutoMediaPlugin } from './embla-plugins/automedia.js';
|
||||
import { Lazyload, LazyloadType } from './embla-plugins/lazyload.js';
|
||||
@@ -66,7 +73,7 @@ export class FrigateCardViewer extends LitElement {
|
||||
}
|
||||
|
||||
const browseMediaQueryParameters =
|
||||
BrowseMediaUtil.getFullDependentBrowseMediaQueryParametersOrDispatchError(
|
||||
getFullDependentBrowseMediaQueryParametersOrDispatchError(
|
||||
this,
|
||||
this.hass,
|
||||
this.cameras,
|
||||
@@ -83,14 +90,13 @@ export class FrigateCardViewer extends LitElement {
|
||||
return;
|
||||
}
|
||||
|
||||
BrowseMediaUtil.fetchLatestMediaAndDispatchViewChange(
|
||||
fetchLatestMediaAndDispatchViewChange(
|
||||
this,
|
||||
this.hass,
|
||||
this.view,
|
||||
BrowseMediaUtil.overrideMultiBrowseMediaQueryParameters(
|
||||
browseMediaQueryParameters,
|
||||
{ mediaType: mediaType },
|
||||
),
|
||||
overrideMultiBrowseMediaQueryParameters(browseMediaQueryParameters, {
|
||||
mediaType: mediaType,
|
||||
}),
|
||||
);
|
||||
return renderProgressIndicator();
|
||||
}
|
||||
@@ -161,8 +167,8 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
||||
i < (target.children || []).length;
|
||||
++i
|
||||
) {
|
||||
if (BrowseMediaUtil.isTrueMedia(target.children[i])) {
|
||||
await ResolvedMediaUtil.resolveMedia(
|
||||
if (isTrueMedia(target.children[i])) {
|
||||
await resolveMedia(
|
||||
this.hass,
|
||||
target.children[i],
|
||||
this.resolvedMediaCache,
|
||||
@@ -321,7 +327,7 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
||||
let prevIndex: number | null = null;
|
||||
for (let i = this.view.childIndex - 1; i >= 0; i--) {
|
||||
const media = this.view.target.children[i];
|
||||
if (media && BrowseMediaUtil.isTrueMedia(media)) {
|
||||
if (media && isTrueMedia(media)) {
|
||||
prevIndex = i;
|
||||
break;
|
||||
}
|
||||
@@ -331,7 +337,7 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
||||
let nextIndex: number | null = null;
|
||||
for (let i = this.view.childIndex + 1; i < this.view.target.children.length; i++) {
|
||||
const media = this.view.target.children[i];
|
||||
if (media && BrowseMediaUtil.isTrueMedia(media)) {
|
||||
if (media && isTrueMedia(media)) {
|
||||
nextIndex = i;
|
||||
break;
|
||||
}
|
||||
@@ -365,7 +371,7 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
||||
return null;
|
||||
}
|
||||
|
||||
const snapshotStartTime = BrowseMediaUtil.getEventStartTime(snapshot);
|
||||
const snapshotStartTime = getEventStartTime(snapshot);
|
||||
if (!snapshotStartTime) {
|
||||
return null;
|
||||
}
|
||||
@@ -383,10 +389,10 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
||||
let latest: number | null = null;
|
||||
for (let i = 0; i < this.view.target.children.length; i++) {
|
||||
const child = this.view.target.children[i];
|
||||
if (!BrowseMediaUtil.isTrueMedia(child)) {
|
||||
if (!isTrueMedia(child)) {
|
||||
continue;
|
||||
}
|
||||
const startTime = BrowseMediaUtil.getEventStartTime(child);
|
||||
const startTime = getEventStartTime(child);
|
||||
|
||||
if (startTime && (earliest === null || startTime < earliest)) {
|
||||
earliest = startTime;
|
||||
@@ -401,7 +407,7 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
||||
|
||||
let clips: FrigateBrowseMediaSource | null;
|
||||
|
||||
const params = BrowseMediaUtil.overrideMultiBrowseMediaQueryParameters(
|
||||
const params = overrideMultiBrowseMediaQueryParameters(
|
||||
this.browseMediaQueryParameters,
|
||||
{
|
||||
mediaType: 'clips',
|
||||
@@ -411,7 +417,7 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
||||
);
|
||||
|
||||
try {
|
||||
clips = await BrowseMediaUtil.multipleBrowseMediaQueryMerged(this.hass, params);
|
||||
clips = await multipleBrowseMediaQueryMerged(this.hass, params);
|
||||
} catch (e) {
|
||||
// This is best effort.
|
||||
return null;
|
||||
@@ -423,10 +429,10 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
||||
|
||||
for (let i = 0; i < clips.children.length; i++) {
|
||||
const child = clips.children[i];
|
||||
if (!BrowseMediaUtil.isTrueMedia(child)) {
|
||||
if (!isTrueMedia(child)) {
|
||||
continue;
|
||||
}
|
||||
const clipStartTime = BrowseMediaUtil.getEventStartTime(child);
|
||||
const clipStartTime = getEventStartTime(child);
|
||||
if (clipStartTime && clipStartTime === snapshotStartTime) {
|
||||
return this.view.evolve({
|
||||
view: 'clip',
|
||||
@@ -487,12 +493,12 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
||||
!this.view ||
|
||||
!this.view.target ||
|
||||
!this.view.target.children ||
|
||||
!BrowseMediaUtil.isTrueMedia(this.view.target.children[childIndex])
|
||||
!isTrueMedia(this.view.target.children[childIndex])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResolvedMediaUtil.resolveMedia(
|
||||
resolveMedia(
|
||||
this.hass,
|
||||
this.view.target.children[childIndex],
|
||||
this.resolvedMediaCache,
|
||||
@@ -664,7 +670,7 @@ export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel {
|
||||
!this.hass ||
|
||||
!this.view ||
|
||||
!this.viewerConfig ||
|
||||
!BrowseMediaUtil.isTrueMedia(mediaToRender) ||
|
||||
!isTrueMedia(mediaToRender) ||
|
||||
!['video', 'image'].includes(mediaToRender.media_content_type)
|
||||
) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user