Tolerate numeric unique_ids.
This commit is contained in:
@@ -216,7 +216,11 @@ export class FrigateCameraManagerEngine
|
|||||||
* @returns The Frigate camera name or null if unavailable.
|
* @returns The Frigate camera name or null if unavailable.
|
||||||
*/
|
*/
|
||||||
protected _getFrigateCameraNameFromEntity(entity: Entity): string | null {
|
protected _getFrigateCameraNameFromEntity(entity: Entity): string | null {
|
||||||
if (entity.unique_id && entity.platform === 'frigate') {
|
if (
|
||||||
|
entity.platform === 'frigate' &&
|
||||||
|
entity.unique_id &&
|
||||||
|
typeof entity.unique_id === 'string'
|
||||||
|
) {
|
||||||
const match = entity.unique_id.match(/:camera:(?<camera>[^:]+)$/);
|
const match = entity.unique_id.match(/:camera:(?<camera>[^:]+)$/);
|
||||||
if (match && match.groups) {
|
if (match && match.groups) {
|
||||||
return match.groups['camera'];
|
return match.groups['camera'];
|
||||||
@@ -238,8 +242,9 @@ export class FrigateCameraManagerEngine
|
|||||||
if (cameraConfig.frigate.camera_name) {
|
if (cameraConfig.frigate.camera_name) {
|
||||||
return (
|
return (
|
||||||
entities.find(
|
entities.find(
|
||||||
(ent) =>
|
(entity) =>
|
||||||
!!ent.unique_id?.match(
|
typeof entity.unique_id === 'string' &&
|
||||||
|
!!entity.unique_id?.match(
|
||||||
new RegExp(`:motion_sensor:${cameraConfig.frigate.camera_name}`),
|
new RegExp(`:motion_sensor:${cameraConfig.frigate.camera_name}`),
|
||||||
),
|
),
|
||||||
)?.entity_id ?? null
|
)?.entity_id ?? null
|
||||||
@@ -262,8 +267,9 @@ export class FrigateCameraManagerEngine
|
|||||||
const addEntityIDIfFound = (cameraOrZone: string, label: string): void => {
|
const addEntityIDIfFound = (cameraOrZone: string, label: string): void => {
|
||||||
const entityID =
|
const entityID =
|
||||||
entities.find(
|
entities.find(
|
||||||
(ent) =>
|
(entity) =>
|
||||||
!!ent.unique_id?.match(
|
typeof entity.unique_id === 'string' &&
|
||||||
|
!!entity.unique_id?.match(
|
||||||
new RegExp(`:occupancy_sensor:${cameraOrZone}_${label}`),
|
new RegExp(`:occupancy_sensor:${cameraOrZone}_${label}`),
|
||||||
),
|
),
|
||||||
)?.entity_id ?? null;
|
)?.entity_id ?? null;
|
||||||
|
|||||||
@@ -93,8 +93,6 @@ import { FrigateCardInitializer } from './utils/initializer.js';
|
|||||||
import 'web-dialog';
|
import 'web-dialog';
|
||||||
import { downloadMedia } from './utils/download.js';
|
import { downloadMedia } from './utils/download.js';
|
||||||
import { getActionsFromQueryString } from './utils/querystring.js';
|
import { getActionsFromQueryString } from './utils/querystring.js';
|
||||||
import { MediaQueries } from './view/media-queries.js';
|
|
||||||
import { MediaQuery } from './camera-manager/types.js';
|
|
||||||
|
|
||||||
/** A note on media callbacks:
|
/** A note on media callbacks:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ export const entitySchema = z.object({
|
|||||||
hidden_by: z.string().nullable(),
|
hidden_by: z.string().nullable(),
|
||||||
platform: z.string(),
|
platform: z.string(),
|
||||||
translation_key: z.string().nullable(),
|
translation_key: z.string().nullable(),
|
||||||
unique_id: z.string().optional(),
|
// Technically the unique_id should be a string, but we want to tolerate
|
||||||
|
// numeric unique_ids also in case they are used. See:
|
||||||
|
// https://github.com/dermotduffy/frigate-hass-card/issues/1016
|
||||||
|
unique_id: z.string().or(z.number()).optional(),
|
||||||
});
|
});
|
||||||
export type Entity = z.infer<typeof entitySchema>;
|
export type Entity = z.infer<typeof entitySchema>;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user