From 656bd5439ec123a6f09cac2d9974b73bb8d53858 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Wed, 19 Jan 2022 21:16:08 -0800 Subject: [PATCH] Rename view.timeout to view.timeout_seconds . --- README.md | 8 ++++---- src/components/image.ts | 2 +- src/config-mgmt.ts | 16 +++++++++++++--- src/const.ts | 2 +- src/editor.ts | 4 ++-- src/localize/languages/en.json | 4 ++-- src/types.ts | 11 +---------- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index d6215aa5..beb77517 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ view: | Option | Default | Overridable | Description | | - | - | - | - | | `default` | `live` | :heavy_multiplication_x: | The view to show in the card by default. See [views](#views) below.| -| `timeout` | | :heavy_multiplication_x: | A numbers of seconds of inactivity after which the card will reset to the default configured view. Inactivity is defined as lack of interaction with the Frigate menu.| +| `timeout_seconds` | | :heavy_multiplication_x: | A numbers of seconds of inactivity after which the card will reset to the default configured view. Inactivity is defined as lack of interaction with the Frigate menu.| | `actions` | | :heavy_multiplication_x: | Actions to use for all views, individual actions may be overriden by view-specific actions. See [actions](#actions) below.| | `update_force` | `false` | :heavy_multiplication_x: | Whether card updates/refreshes should ignore playing media and human interaction. See [card updates](#card-updates) below for behavior and usecases.| | `update_entities` | | :heavy_multiplication_x: | **YAML only**: A list of entity ids that should cause the view to reset to the default. See [card updates](#card-updates) below for behavior and usecases.| @@ -572,7 +572,7 @@ This card supports several different views: |`snapshot`|Shows an event viewer for the most recent snapshot for this camera/zone/label. Can also be accessed by holding down the `snapshots` menu icon.| |`clips`|Shows an event gallery of clips for this camera/zone/label.| |`clip`|Shows an event viewer for the most recent clip for this camera/zone/label. Can also be accessed by holding down the `clips` menu icon.| -|`image`|Shows a static image specified by the `image` parameter, can be used as a discrete default view or a screensaver (via `view_timeout`).| +|`image`|Shows a static image specified by the `image` parameter, can be used as a discrete default view or a screensaver (via `view.timeout_seconds`).| ### Navigating From A Snapshot To A Clip @@ -1105,7 +1105,7 @@ The following table describes the behavior these 3 flags have. ### Card Update Truth Table -| `view.timeout` | `view.update_force` | `view.update_entities` | Behavior | +| `view.timeout_seconds` | `view.update_force` | `view.update_entities` | Behavior | | :-: | :-: | :-: | - | | Unset or `0` | *(Any value)* | Unset | Card will not automatically refresh. | | Unset or `0` | `false` | *(Any entity)* | Card will reload default view when entity state changes, unless media is playing. | @@ -1121,7 +1121,7 @@ The following table describes the behavior these 3 flags have. ```yaml view: default: live - timeout: 30 + timeout_seconds: 30 force: true ``` * Using `clip` or `snapshot` as the default view (for the most recent clip or diff --git a/src/components/image.ts b/src/components/image.ts index e2052e3f..8ca1f816 100644 --- a/src/components/image.ts +++ b/src/components/image.ts @@ -26,9 +26,9 @@ export class CachedValueController implements ReactiveController { protected _timerID?: number; constructor(host: ReactiveControllerHost, timerSeconds: number, callback: () => T) { - (this._host = host).addController(this); this._timerSeconds = timerSeconds; this._callback = callback; + (this._host = host).addController(this); } public removeController(): void { diff --git a/src/config-mgmt.ts b/src/config-mgmt.ts index a80b9e1b..12de5bd6 100644 --- a/src/config-mgmt.ts +++ b/src/config-mgmt.ts @@ -20,7 +20,7 @@ import { CONF_MENU_MODE, CONF_OVERRIDES, CONF_VIEW_DEFAULT, - CONF_VIEW_TIMEOUT, + CONF_VIEW_TIMEOUT_SECONDS, CONF_VIEW_UPDATE_ENTITIES, } from './const'; import { RawFrigateCardConfig, RawFrigateCardConfigArray } from './types'; @@ -129,13 +129,22 @@ export const copyConfig = function (obj: RawFrigateCardConfig): RawFrigateCardCo /** * Determines if a property is not an object. - * @param value The property. + * @param value The value. * @returns `true` is the value is not an object. */ const isNotObject = function (value: unknown) { return typeof value !== 'object' ? value : undefined; }; +/** + * Converts to a number or return undefined. + * @param value The value. + * @returns A number or undefined. + */ +const toNumberOrIgnore = function (value: unknown) { + return isNaN(value as number) ? undefined : Number(value) +}; + /** * Move a property from one location to another. * @param obj The configuration object in which the property resides. @@ -265,7 +274,7 @@ const UPGRADES = [ upgradeMoveTo('label', 'frigate.label'), upgradeMoveTo('zone', 'frigate.zone'), upgradeMoveTo('view_default', CONF_VIEW_DEFAULT), - upgradeMoveTo('view_timeout', CONF_VIEW_TIMEOUT), + upgradeMoveTo('view_timeout', 'view.timeout'), upgradeMoveTo('live_provider', 'live.provider'), upgradeMoveTo('live_preload', CONF_LIVE_PRELOAD), upgradeMoveTo('webrtc', 'live.webrtc'), @@ -283,4 +292,5 @@ const UPGRADES = [ // v2.1.0 -> v3.0.0 upgradeToMultipleCameras(), updateMenuConditionToMenuOverride(), + upgradeMoveTo('view.timeout', CONF_VIEW_TIMEOUT_SECONDS, toNumberOrIgnore), ]; diff --git a/src/const.ts b/src/const.ts index c22b7745..97a0ab88 100644 --- a/src/const.ts +++ b/src/const.ts @@ -20,7 +20,7 @@ export const CONF_CAMERAS_ARRAY_LIVE_PROVIDER = `${CONF_CAMERAS}.#.live_provider export const CONF_VIEW = 'view' as const; export const CONF_VIEW_DEFAULT = `${CONF_VIEW}.default` as const; -export const CONF_VIEW_TIMEOUT = `${CONF_VIEW}.timeout` as const; +export const CONF_VIEW_TIMEOUT_SECONDS = `${CONF_VIEW}.timeout_seconds` as const; export const CONF_VIEW_UPDATE_FORCE = `${CONF_VIEW}.update_force` as const; export const CONF_VIEW_UPDATE_ENTITIES = `${CONF_VIEW}.update_entities` as const; diff --git a/src/editor.ts b/src/editor.ts index 4da5ec43..339600a2 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -56,7 +56,7 @@ import { CONF_MENU_BUTTON_SIZE, CONF_MENU_MODE, CONF_VIEW_DEFAULT, - CONF_VIEW_TIMEOUT, + CONF_VIEW_TIMEOUT_SECONDS, CONF_VIEW_UPDATE_FORCE, } from './const.js'; import { arrayMove, getEntityTitle, prettifyFrigateName } from './common.js'; @@ -657,7 +657,7 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor ? html`
${this._renderDropdown(CONF_VIEW_DEFAULT, viewModes)} - ${this._renderStringInput(CONF_VIEW_TIMEOUT, 'number')} + ${this._renderStringInput(CONF_VIEW_TIMEOUT_SECONDS, 'number')} ${this._renderSwitch(CONF_VIEW_UPDATE_FORCE, defaults.view.update_force)}
` diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index de88faab..9002c31f 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -41,7 +41,7 @@ "snapshots": "Snapshots gallery", "image": "Static image" }, - "timeout": "View timeout secs (before returning to default, 0=never)", + "timeout_seconds": "View timeout seconds (before returning to default, 0=never)", "update_force": "Force card updates (ignore media playing / interaction)" }, "event_gallery": { @@ -99,7 +99,7 @@ }, "image": { "src": "Static image URL/data for image view", - "refresh_seconds": "Number of seconds after which to refresh" + "refresh_seconds": "Number of seconds after which to refresh (0=never)" }, "menu": { "buttons": { diff --git a/src/types.ts b/src/types.ts index 36cc05e0..8f666031 100644 --- a/src/types.ts +++ b/src/types.ts @@ -371,16 +371,7 @@ const viewConfigSchema = z .enum(FRIGATE_CARD_VIEWS_USER_SPECIFIED) .optional() .default(viewConfigDefault.default), - timeout: z - .number() - .or( - z - .string() - .regex(/^\d+$/) - .transform((val) => Number(val)), - ) - .optional() - .default(viewConfigDefault.timeout), + timeout_seconds: z.number().default(viewConfigDefault.timeout), update_force: z.boolean().default(viewConfigDefault.update_force), update_entities: z.string().array().optional(), })