Handle media metadata exceptions.
This commit is contained in:
@@ -34,11 +34,11 @@ import {
|
|||||||
} from './media-filter-core';
|
} from './media-filter-core';
|
||||||
import './surround.js';
|
import './surround.js';
|
||||||
import './timeline-core.js';
|
import './timeline-core.js';
|
||||||
import { EventQuery, QueryType, RecordingQuery } from '../camera/types';
|
import { EventQuery, MediaMetadata, QueryType, RecordingQuery } from '../camera/types';
|
||||||
import { EventMediaQueries, RecordingMediaQueries } from '../view/media-queries';
|
import { EventMediaQueries, RecordingMediaQueries } from '../view/media-queries';
|
||||||
import { createViewForEvents, createViewForRecordings } from '../utils/media-to-view.js';
|
import { createViewForEvents, createViewForRecordings } from '../utils/media-to-view.js';
|
||||||
import { HomeAssistant } from 'custom-card-helpers';
|
import { HomeAssistant } from 'custom-card-helpers';
|
||||||
import { prettifyTitle } from '../utils/basic';
|
import { errorToConsole, prettifyTitle } from '../utils/basic';
|
||||||
import format from 'date-fns/format';
|
import format from 'date-fns/format';
|
||||||
import parse from 'date-fns/parse';
|
import parse from 'date-fns/parse';
|
||||||
import endOfMonth from 'date-fns/endOfMonth';
|
import endOfMonth from 'date-fns/endOfMonth';
|
||||||
@@ -242,41 +242,50 @@ export class MediaMetadataController implements ReactiveController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async hostConnected() {
|
async hostConnected() {
|
||||||
const metadata = await this._cameraManager.getMediaMetadata(this._hass);
|
let metadata: MediaMetadata | null;
|
||||||
if (metadata) {
|
try {
|
||||||
if (metadata.what) {
|
metadata = await this._cameraManager.getMediaMetadata(this._hass);
|
||||||
this.whatOptions = [...metadata.what]
|
} catch (e) {
|
||||||
.sort()
|
errorToConsole(e as Error);
|
||||||
.map((what) => ({ value: what, label: prettifyTitle(what) }));
|
return;
|
||||||
}
|
|
||||||
if (metadata.where) {
|
|
||||||
this.whereOptions = [...metadata.where]
|
|
||||||
.sort()
|
|
||||||
.map((where) => ({ value: where, label: prettifyTitle(where) }));
|
|
||||||
}
|
|
||||||
if (metadata.days) {
|
|
||||||
const yearMonths: Set<string> = new Set();
|
|
||||||
[...metadata.days].forEach((day) => {
|
|
||||||
// An efficient conversion: "2023-01-26" -> "2023-01"
|
|
||||||
yearMonths.add(day.substring(0, 7));
|
|
||||||
});
|
|
||||||
const monthStarts: Date[] = [];
|
|
||||||
yearMonths.forEach((yearMonth) => {
|
|
||||||
monthStarts.push(parse(yearMonth, 'yyyy-MM', new Date()));
|
|
||||||
});
|
|
||||||
this.whenOptions = monthStarts
|
|
||||||
.sort()
|
|
||||||
.reverse()
|
|
||||||
.map((monthStart) => ({
|
|
||||||
label: format(monthStart, 'MMMM yyyy'),
|
|
||||||
value: {
|
|
||||||
selection: MediaFilterCoreWhen.Custom,
|
|
||||||
custom: { start: monthStart, end: endOfMonth(monthStart) },
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
this._host.requestUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!metadata) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadata.what) {
|
||||||
|
this.whatOptions = [...metadata.what]
|
||||||
|
.sort()
|
||||||
|
.map((what) => ({ value: what, label: prettifyTitle(what) }));
|
||||||
|
}
|
||||||
|
if (metadata.where) {
|
||||||
|
this.whereOptions = [...metadata.where]
|
||||||
|
.sort()
|
||||||
|
.map((where) => ({ value: where, label: prettifyTitle(where) }));
|
||||||
|
}
|
||||||
|
if (metadata.days) {
|
||||||
|
const yearMonths: Set<string> = new Set();
|
||||||
|
[...metadata.days].forEach((day) => {
|
||||||
|
// An efficient conversion: "2023-01-26" -> "2023-01"
|
||||||
|
yearMonths.add(day.substring(0, 7));
|
||||||
|
});
|
||||||
|
const monthStarts: Date[] = [];
|
||||||
|
yearMonths.forEach((yearMonth) => {
|
||||||
|
monthStarts.push(parse(yearMonth, 'yyyy-MM', new Date()));
|
||||||
|
});
|
||||||
|
this.whenOptions = monthStarts
|
||||||
|
.sort()
|
||||||
|
.reverse()
|
||||||
|
.map((monthStart) => ({
|
||||||
|
label: format(monthStart, 'MMMM yyyy'),
|
||||||
|
value: {
|
||||||
|
selection: MediaFilterCoreWhen.Custom,
|
||||||
|
custom: { start: monthStart, end: endOfMonth(monthStart) },
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
this._host.requestUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,6 @@
|
|||||||
// - TODO: Handle all TODOs in media filter and media filter core.
|
// - TODO: Handle all TODOs in media filter and media filter core.
|
||||||
// - TODO: Make media filter slot choice configurable (gallery.ts).
|
// - TODO: Make media filter slot choice configurable (gallery.ts).
|
||||||
// - TODO: Filter panel expands from right can occasionally 'stick' open.
|
// - TODO: Filter panel expands from right can occasionally 'stick' open.
|
||||||
// - TODO: Media type selection, i.e. events or recordings.
|
|
||||||
// - TODO: Cache every summary.
|
|
||||||
|
|
||||||
// Hard:
|
// Hard:
|
||||||
// - TODO: Implement gallery.
|
// - TODO: Implement gallery.
|
||||||
|
|||||||
Reference in New Issue
Block a user