From 0128e2a818bbf19d67c8c52e134a78d5fc0fd90f Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Tue, 14 Feb 2023 19:15:33 -0800 Subject: [PATCH] Rename frigate_ui action to camera_ui . --- README.md | 12 ++++++------ src/card.ts | 8 ++++---- src/config-mgmt.ts | 28 ++++++++++++++++++++++++++-- src/const.ts | 2 +- src/editor.ts | 2 +- src/localize/languages/en.json | 2 +- src/localize/languages/it.json | 2 +- src/localize/languages/pt-BR.json | 2 +- src/types.ts | 6 +++--- 9 files changed, 44 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index cd9857e2..b6ac4446 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,7 @@ menu: | `recordings` | :white_check_mark: | The `recordings` view menu button: brings the user to the `recordings` view on tap and the most-recent `recording` view on hold. See [views](#views) below. This button will never be shown if the `frigate.camera_name` for the selected camera is not auto-detected/specified (e.g. non-Frigate cameras), or if the `frigate.camera_name` is `birdseye`.| | `image` | :white_check_mark: | The `image` view menu button: brings the user to the static `image` view. See [views](#views) below.| | `download` | :white_check_mark: | The `download` menu button: allow direct download of the media being displayed.| -| `frigate_ui` | :white_check_mark: | The `frigate_ui` menu button: brings the user to a context-appropriate page on the Frigate UI (e.g. the camera homepage). Will only appear if the `frigate.url` option is set.| +| `camera_ui` | :white_check_mark: | The `camera_ui` menu button: brings the user to a context-appropriate page on the UI of their camera engine (e.g. the Frigate camera homepage). Will only appear if the camera engine supports a camera UI (e.g. if `frigate.url` option is set for `frigate` engine users).| | `fullscreen` | :white_check_mark: | The `fullscreen` menu button: expand the card to consume the fullscreen. | | `timeline` | :white_check_mark: | The `timeline` menu button: show the event timeline. | | `media_player` | :white_check_mark: | The `media_player` menu button: sends the visible media to a remote media player. Supports Frigate clips, snapshots and live camera (only for cameras that specify a `camera_entity` and only using the default HA stream (equivalent to the `ha` live provider). `jsmpeg` or `webrtc-card` are not supported, although live can still be played as long as `camera_entity` is specified. In the player list, a `tap` will send the media to the player, a `hold` will stop the media on the player. | @@ -1057,7 +1057,7 @@ Parameters for the `custom:frigate-card-ptz` element: | Parameter | Description | | - | - | | `action` | Must be `custom:frigate-card-action`. | -| `frigate_card_action` | Call a Frigate Card action. Acceptable values are `default`, `clip`, `clips`, `image`, `live`, `recording`, `recordings`, `snapshot`, `snapshots`, `download`, `timeline`, `frigate_ui`, `fullscreen`, `camera_select`, `menu_toggle`, `media_player`.| +| `frigate_card_action` | Call a Frigate Card action. Acceptable values are `default`, `clip`, `clips`, `image`, `live`, `recording`, `recordings`, `snapshot`, `snapshots`, `download`, `timeline`, `camera_ui`, `fullscreen`, `camera_select`, `menu_toggle`, `media_player`.| ##### Command descriptions @@ -1066,7 +1066,7 @@ Parameters for the `custom:frigate-card-ptz` element: | `default` | Trigger the default view. | | `clip`, `clips`, `image`, `live`, `recording`, `recordings`, `snapshot`, `snapshots` | Trigger the named [view](#views).| |`download`|Download the displayed media.| -|`frigate_ui`|Open the Frigate UI at the configured URL.| +|`camera_ui`|Open the Frigate UI at the configured URL.| |`fullscreen`|Toggle fullscreen.| |`camera_select`|Select a given camera. Takes a single additional `camera` parameter with the [camera ID](#camera-ids) of the camera to select. Respects the value of `view.camera_select` to choose the appropriate view on the new camera.| |`menu_toggle` | Show/hide the menu (for the `hidden` mode style). | @@ -1455,7 +1455,7 @@ menu: enabled: true alignment: matching icon: mdi:download - frigate_ui: + camera_ui: priority: 50 enabled: true alignment: matching @@ -1976,7 +1976,7 @@ elements: title: Open Frigate UI tap_action: action: custom:frigate-card-action - frigate_card_action: frigate_ui + frigate_card_action: camera_ui - type: custom:frigate-card-menu-icon icon: mdi:alpha-j-circle title: Change to fullscreen @@ -2175,7 +2175,7 @@ overrides: enabled: true alignment: matching icon: mdi:download - frigate_ui: + camera_ui: priority: 50 enabled: true alignment: matching diff --git a/src/card.ts b/src/card.ts index 5d7e234b..61ec4c25 100644 --- a/src/card.ts +++ b/src/card.ts @@ -531,11 +531,11 @@ class FrigateCard extends LitElement { if (this._getCameraURLFromContext()) { buttons.push({ icon: 'mdi:web', - ...this._getConfig().menu.buttons.frigate_ui, + ...this._getConfig().menu.buttons.camera_ui, type: 'custom:frigate-card-menu-icon', - title: localize('config.menu.buttons.frigate_ui'), + title: localize('config.menu.buttons.camera_ui'), tap_action: createFrigateCardCustomAction( - 'frigate_ui', + 'camera_ui', ) as FrigateCardCustomAction, }); } @@ -1337,7 +1337,7 @@ class FrigateCard extends LitElement { case 'download': this._downloadViewerMedia(); break; - case 'frigate_ui': + case 'camera_ui': const url = this._getCameraURLFromContext(); if (url) { window.open(url); diff --git a/src/config-mgmt.ts b/src/config-mgmt.ts index 64c39f12..4a8f319e 100644 --- a/src/config-mgmt.ts +++ b/src/config-mgmt.ts @@ -18,10 +18,10 @@ import { CONF_MEDIA_VIEWER, CONF_MENU, CONF_MENU_BUTTONS_CAMERAS, + CONF_MENU_BUTTONS_CAMERA_UI, CONF_MENU_BUTTONS_CLIPS, CONF_MENU_BUTTONS_DOWNLOAD, CONF_MENU_BUTTONS_FRIGATE, - CONF_MENU_BUTTONS_FRIGATE_UI, CONF_MENU_BUTTONS_FULLSCREEN, CONF_MENU_BUTTONS_IMAGE, CONF_MENU_BUTTONS_LIVE, @@ -599,6 +599,24 @@ const transformConditionMediaLoaded = (data: unknown): boolean => { return false; }; +/** + * Transform action frigate_ui -> camera_ui + * @param data Input data. + * @returns `true` if the configuration was modified. + */ +const transformFrigateUIAction = (data: unknown): boolean => { + if ( + typeof data === 'object' && + data && + data['action'] === 'custom:frigate-card-action' && + data['frigate_card_action'] === 'frigate_ui' + ) { + data['frigate_card_action'] = 'camera_ui'; + return true; + } + return false; +}; + const UPGRADES = [ // v1.2.1 -> v2.0.0 upgradeMoveTo('frigate_url', 'frigate.url'), @@ -671,7 +689,7 @@ const UPGRADES = [ upgradeWithOverrides(CONF_MENU_BUTTONS_SNAPSHOTS, menuButtonBooleanToObject), upgradeWithOverrides(CONF_MENU_BUTTONS_IMAGE, menuButtonBooleanToObject), upgradeWithOverrides(CONF_MENU_BUTTONS_DOWNLOAD, menuButtonBooleanToObject), - upgradeWithOverrides(CONF_MENU_BUTTONS_FRIGATE_UI, menuButtonBooleanToObject), + upgradeWithOverrides('menu.buttons.frigate_ui', menuButtonBooleanToObject), upgradeWithOverrides(CONF_MENU_BUTTONS_FULLSCREEN, menuButtonBooleanToObject), upgrade(CONF_LIVE_LAZY_UNLOAD, (val) => typeof val === 'boolean' ? (val ? 'all' : 'never') : undefined, @@ -711,4 +729,10 @@ const UPGRADES = [ )(typeof data === 'object' && data ? data[CONF_ELEMENTS] : {}); }, upgradeMoveToWithOverrides('event_gallery', CONF_MEDIA_GALLERY), + upgradeMoveToWithOverrides('menu.buttons.frigate_ui', CONF_MENU_BUTTONS_CAMERA_UI), + (data: unknown): boolean => { + return recursiveUpgradeObject(transformFrigateUIAction)( + typeof data === 'object' && data ? data : {}, + ); + }, ]; diff --git a/src/const.ts b/src/const.ts index 17a77985..0e49a7a4 100644 --- a/src/const.ts +++ b/src/const.ts @@ -194,7 +194,7 @@ export const CONF_MENU_BUTTONS_CAMERAS = `${CONF_MENU}.buttons.cameras` as const export const CONF_MENU_BUTTONS_CLIPS = `${CONF_MENU}.buttons.clips` as const; export const CONF_MENU_BUTTONS_DOWNLOAD = `${CONF_MENU}.buttons.download` as const; export const CONF_MENU_BUTTONS_FRIGATE = `${CONF_MENU}.buttons.frigate` as const; -export const CONF_MENU_BUTTONS_FRIGATE_UI = `${CONF_MENU}.buttons.frigate_ui` as const; +export const CONF_MENU_BUTTONS_CAMERA_UI = `${CONF_MENU}.buttons.camera_ui` as const; export const CONF_MENU_BUTTONS_FULLSCREEN = `${CONF_MENU}.buttons.fullscreen` as const; export const CONF_MENU_BUTTONS_IMAGE = `${CONF_MENU}.buttons.image` as const; export const CONF_MENU_BUTTONS_LIVE = `${CONF_MENU}.buttons.live` as const; diff --git a/src/editor.ts b/src/editor.ts index 8a456f90..8bb23319 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -1579,7 +1579,7 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor ${this._renderMenuButton('recordings')} ${this._renderMenuButton('image') /* */} ${this._renderMenuButton('download')} - ${this._renderMenuButton('frigate_ui')} + ${this._renderMenuButton('camera_ui')} ${this._renderMenuButton('fullscreen')} ${this._renderMenuButton('timeline')} ${this._renderMenuButton('media_player')} diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index dd775b04..c11e8476 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -215,12 +215,12 @@ "matching": "Matching the menu alignment", "opposing": "Opposing the menu alignment" }, + "camera_ui": "Camera user interface", "cameras": "Cameras", "clips": "Clips", "download": "Download", "enabled": "Button enabled", "frigate": "Frigate menu / Default view", - "frigate_ui": "Frigate user interface", "fullscreen": "Fullscreen", "icon": "Icon", "image": "Image", diff --git a/src/localize/languages/it.json b/src/localize/languages/it.json index 6c9db02e..1d3204fe 100644 --- a/src/localize/languages/it.json +++ b/src/localize/languages/it.json @@ -209,12 +209,12 @@ "matching": "Corrispondenza con l'allineamento del menu", "opposing": "Contrastare l'allineamento del menu" }, + "camera_ui": "", "cameras": "Telecamere", "clips": "Clip", "download": "Download", "enabled": "Pulsante abilitato", "frigate": "Frigate menu / Visualizzazione predefinita", - "frigate_ui": "Frigate interfaccia utente", "fullscreen": "A schermo intero", "icon": "Icona", "image": "Immagine", diff --git a/src/localize/languages/pt-BR.json b/src/localize/languages/pt-BR.json index 78ca48b3..3af8326e 100644 --- a/src/localize/languages/pt-BR.json +++ b/src/localize/languages/pt-BR.json @@ -209,12 +209,12 @@ "matching": "Mesmo alinhamento do menu", "opposing": "Opor-se ao alinhamento do menu" }, + "camera_ui": "", "cameras": "Selecionar câmera", "clips": "Clipes", "download": "Baixe a mídia do evento", "enabled": "Botão ativado", "frigate": "Frigate menu / Visualização padrão", - "frigate_ui": "Frigate Interface de usuário", "fullscreen": "Tela cheia", "icon": "Ícone", "image": "Imagem", diff --git a/src/types.ts b/src/types.ts index a8564b47..2b0ae257 100644 --- a/src/types.ts +++ b/src/types.ts @@ -210,7 +210,7 @@ const FRIGATE_CARD_GENERAL_ACTIONS = [ 'snapshots', 'timeline', 'download', - 'frigate_ui', + 'camera_ui', 'fullscreen', 'menu_toggle', 'diagnostics', @@ -937,7 +937,7 @@ const menuConfigDefault = { image: hiddenButtonDefault, timeline: visibleButtonDefault, download: visibleButtonDefault, - frigate_ui: visibleButtonDefault, + camera_ui: visibleButtonDefault, fullscreen: visibleButtonDefault, media_player: visibleButtonDefault, recordings: hiddenButtonDefault, @@ -969,7 +969,7 @@ const menuConfigSchema = z image: hiddenButtonSchema.default(menuConfigDefault.buttons.image), timeline: visibleButtonSchema.default(menuConfigDefault.buttons.timeline), download: visibleButtonSchema.default(menuConfigDefault.buttons.download), - frigate_ui: visibleButtonSchema.default(menuConfigDefault.buttons.frigate_ui), + camera_ui: visibleButtonSchema.default(menuConfigDefault.buttons.camera_ui), fullscreen: visibleButtonSchema.default(menuConfigDefault.buttons.fullscreen), media_player: visibleButtonSchema.default( menuConfigDefault.buttons.media_player,