Revert "Convert camera configuration to YAML dictionary."

This reverts commit 37458a299d458d5687db35f046669eff26793112.
This commit is contained in:
Dermot Duffy
2022-01-14 21:31:16 -08:00
parent 86b26383d0
commit b03c8b4020
4 changed files with 26 additions and 22 deletions
+19 -15
View File
@@ -403,13 +403,8 @@ export class FrigateCard extends LitElement {
protected async _loadCameras(): Promise<void> { protected async _loadCameras(): Promise<void> {
const cameras: Map<string, CameraConfig> = new Map(); const cameras: Map<string, CameraConfig> = new Map();
const addCameraConfig = async (id: string, config: CameraConfig) => { const addCameraConfig = async (config: CameraConfig) => {
if (!config.camera_name && (config.camera_entity || id.startsWith('camera.'))) { if (!config.camera_name && config.camera_entity) {
if (!config.camera_entity) {
// If the camera_entity isn't explicitly set and the id looks like
// one, use that.
config.camera_entity = id;
}
const resolvedName = await this._getFrigateCameraNameFromEntity( const resolvedName = await this._getFrigateCameraNameFromEntity(
config.camera_entity, config.camera_entity,
); );
@@ -417,17 +412,26 @@ export class FrigateCard extends LitElement {
config.camera_name = resolvedName; config.camera_name = resolvedName;
} }
} }
if (!config.camera_name) {
config.camera_name = id; if (config.camera_name) {
} const id = config.card_id || config.camera_entity || config.camera_name;
if (cameras.has(id)) {
this._setMessageAndUpdate(
{
message: localize('error.duplicate_frigate_camera_name'),
type: 'error',
},
true,
);
} else {
cameras.set(id, config); cameras.set(id, config);
}
}
}; };
await Promise.all( if (this.config.camera && Array.isArray(this.config.camera)) {
Object.keys(this.config.cameras).map((key) => await Promise.all(this.config.camera.map(addCameraConfig.bind(this)));
addCameraConfig(key, this.config.cameras[key]), }
),
);
if (!cameras.size) { if (!cameras.size) {
return this._setMessageAndUpdate( return this._setMessageAndUpdate(
+3 -4
View File
@@ -287,8 +287,7 @@ export function convertActionToFrigateCardCustomAction(
*/ */
export function createFrigateCardCustomAction( export function createFrigateCardCustomAction(
action: FrigateCardAction, action: FrigateCardAction,
camera?: string, camera?: string): FrigateCardCustomAction | undefined {
): FrigateCardCustomAction | undefined {
if (action == 'camera_select') { if (action == 'camera_select') {
if (!camera) { if (!camera) {
return undefined; return undefined;
@@ -297,12 +296,12 @@ export function createFrigateCardCustomAction(
action: 'fire-dom-event', action: 'fire-dom-event',
frigate_card_action: action, frigate_card_action: action,
camera: camera, camera: camera,
}; }
} }
return { return {
action: 'fire-dom-event', action: 'fire-dom-event',
frigate_card_action: action, frigate_card_action: action,
}; }
} }
/** /**
+1
View File
@@ -154,6 +154,7 @@
"upgrade_available": "An automated card configuration upgrade is available, please visit the visual card editor", "upgrade_available": "An automated card configuration upgrade is available, please visit the visual card editor",
"missing_webrtc": "WebRTC component not found", "missing_webrtc": "WebRTC component not found",
"no_cameras": "No cameras found, you must configure at least one camera configured with a camera_entity or camera_name", "no_cameras": "No cameras found, you must configure at least one camera configured with a camera_entity or camera_name",
"duplicate_frigate_camera_name": "Duplicate Frigate camera name, use the 'id' parameter to uniquely identify them",
"could_not_render_elements": "Could not render picture elements", "could_not_render_elements": "Could not render picture elements",
"invalid_elements_config": "Invalid picture elements configuration", "invalid_elements_config": "Invalid picture elements configuration",
"jsmpeg_no_sign": "Could not retrieve or sign JSMPEG websocket path", "jsmpeg_no_sign": "Could not retrieve or sign JSMPEG websocket path",
+3 -3
View File
@@ -368,12 +368,12 @@ const cameraConfigDefaultSchema = z
// specified). // specified).
icon: z.string().optional(), icon: z.string().optional(),
title: z.string().optional(), title: z.string().optional(),
card_id: z.string().optional(),
}) })
.default(cameraConfigDefault); .default(cameraConfigDefault);
export type CameraConfig = z.infer<typeof cameraConfigDefaultSchema>; export type CameraConfig = z.infer<typeof cameraConfigDefaultSchema>;
const camerasConfigDefaultSchema = z.record(cameraConfigDefaultSchema);
/** /**
* View configuration section. * View configuration section.
*/ */
@@ -650,7 +650,7 @@ const dimensionsConfigSchema = z
*/ */
export const frigateCardConfigSchema = z.object({ export const frigateCardConfigSchema = z.object({
// Main configuration sections. // Main configuration sections.
cameras: camerasConfigDefaultSchema, camera: cameraConfigDefaultSchema.array().nonempty(),
view: viewConfigSchema, view: viewConfigSchema,
menu: menuConfigSchema, menu: menuConfigSchema,
live: liveConfigSchema, live: liveConfigSchema,