From 27ab146cb5d122d259c031f6fecef46b8da06389 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Fri, 13 Aug 2021 19:45:00 -0700 Subject: [PATCH] Add tooltip to events with event information. --- package.json | 1 + src/frigate-card.ts | 28 ++++++++++++++++++++++++++-- tsconfig.json | 3 ++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 102173fc..7f96abab 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "dependencies": { "@material/image-list": "^12.0.0", "custom-card-helpers": "^1.7.1", + "dayjs": "^1.10.6", "home-assistant-js-websocket": "^5.11.1", "lit-element": "^2.5.1", "lit-html": "^1.4.1", diff --git a/src/frigate-card.ts b/src/frigate-card.ts index 58264ded..ae28af49 100644 --- a/src/frigate-card.ts +++ b/src/frigate-card.ts @@ -1,9 +1,9 @@ // TODO Make editor work. // TODO Add title to clips / snapshots playing/viewing -// TODO Add tooltips for gallary clips with details of event. -// TODO Sometimes webrtc component shows up as not found in browser (maybe after fresh build?) +// TODO Try new navbar idea // TODO Add gallery item to take to media browser // TODO Add documentation & screenshots. +// TODO Sometimes webrtc component shows up as not found in browser (maybe after fresh build?) /* eslint-disable @typescript-eslint/no-explicit-any */ import { @@ -34,6 +34,13 @@ import { frigateCardConfigSchema, frigateGetEventsResponseSchema } from './types import type { FrigateCardConfig, FrigateEvent, FrigateGetEventsResponse, GetEventsParameters, ControlVideosParameters } from './types'; import { CARD_VERSION } from './const'; import { localize } from './localize/localize'; +import dayjs from 'dayjs'; +import dayjs_utc from 'dayjs/plugin/utc'; +import dayjs_timezone from 'dayjs/plugin/timezone'; + +// Load dayjs plugins. +dayjs.extend(dayjs_timezone); +dayjs.extend(dayjs_utc); /* eslint no-console: 0 */ console.info( @@ -255,6 +262,22 @@ export class FrigateCard extends LitElement { return this._renderAttentionIcon("mdi:alert-circle"); } + // Generate a human-readable title from an event. + // MediaBrowser title: 2021-08-12 19:20:14 [10s, Person 76%] + protected _getEventTitle(event: FrigateEvent) : string { + const date = dayjs.unix(event.end_time).tz("UTC").local(); + + const iso_datetime = date.format("YYYY-MM-DD HH:mm:ss"); + const duration = Math.trunc(event.end_time > event.start_time ? + event.end_time - event.start_time : 0); + const score = Math.trunc(event.top_score*100); + + // Capitalize the label. + const label = event.label.charAt(0).toUpperCase() + event.label.slice(1); + + return `${iso_datetime} [${duration}s, ${label} ${score}%]`; + } + // Render Frigate events into a card gallery. protected async _renderEvents() : Promise { const want_clips = this._viewMode == FrigateCardView.CLIPS; @@ -278,6 +301,7 @@ export class FrigateCard extends LitElement {
  • { diff --git a/tsconfig.json b/tsconfig.json index cfd5d3a2..71a1e81d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,7 @@ "noImplicitAny": false, "skipLibCheck": true, "resolveJsonModule": true, - "experimentalDecorators": true + "experimentalDecorators": true, + "esModuleInterop": true, } } \ No newline at end of file