diff --git a/README.md b/README.md index d57fbfdc..83919295 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ All variables listed are under a `view:` section. | - | - | - | | `default` | `live` | The view to show in the card by default. See [views](#views) below.| | `timeout` | | 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` | | Actions to use for all views, individual actions may be overriden by view-specific actions. See [actions](#actions) below.| ### Menu options @@ -113,6 +114,7 @@ All variables listed are under a `live:` section. | `webrtc.url` | | The RTSP url to pass to WebRTC. Specify this OR `webrtc.entity` (below).| | `webrtc.entity` | | The RTSP entity to pass WebRTC. Specify this OR `webrtc.url` (above). | | `webrtc.*`| | Any other options in a `webrtc:` YAML dictionary are silently passed through to WebRTC. See [WebRTC Configuration](https://github.com/AlexxIT/WebRTC#configuration) for full details this external card provides.| +| `actions` | | Actions to use for the `live` view. See [actions](#actions) below.| #### Available Live Providers @@ -124,7 +126,7 @@ All variables listed are under a `live:` section. ### Event Viewer options -All variables listed are under a `event_viewer:` section. +The `event_viewer` is used for viewing all `clip` and `snapshot` media, in a media carousel. All variables listed are under a `event_viewer:` section. | Option | Default | Description | | - | - | - | @@ -133,6 +135,15 @@ All variables listed are under a `event_viewer:` section. | `draggable` | `true` | Whether or not the event viewer carousel can be dragged left or right, via touch/swipe and mouse dragging. | | `controls.next_previous.style` | `thumbnails` | When viewing media, what kind of controls to show to move to the previous/next media item. Acceptable values: `thumbnails`, `chevrons`, `none` . | | `controls.next_previous.size` | `48px` | The size of the next/previous controls (in CSS Units)[https://www.w3schools.com/cssref/css_units.asp].| +| `actions` | | Actions to use for all views that use the `event_viewer` (e.g. `clip`, `snapshot`). See [actions](#actions) below.| + +### Event Gallery options + +The `event_gallery` is used for providing an overview of all `clips` and `snapshots` in a thumbnail gallery. All variables listed are under a `event_gallery:` section. + +| Option | Default | Description | +| - | - | - | +| `actions` | | Actions to use for all views that use the `event_gallery` (e.g. `clips`, `snapshots`). See [actions](#actions) below.| ### Image options @@ -141,6 +152,7 @@ All variables listed are under a `image:` section. | Option | Default | Description | | - | - | - | | `src` | [embedded image](https://www.flickr.com/photos/dianasch/47543120431) | A static image URL for use with the `image` [view](#views).| +| `actions` | | Actions to use for the `image` view. See [actions](#actions) below.| ### Dimension options @@ -457,6 +469,8 @@ elements: ``` + + #### Triggering card actions You can control the card itself with the `custom:frigate-card-action` action. @@ -516,10 +530,49 @@ See the [other options](#other-options) above. Clicking on a snapshot will take the user to a clip that was taken at the ~same time as the snapshot (if any). -### Getting event details + -More details about an event can be found by clicking the 'globe' icon in the -menu, which takes the user to the Frigate page for that event. +## Card & View Actions + +Actions may be attached to the card itself, to trigger action when the card +experiences a `tap`, `double_tap` or `hold` event. These actions can be +specified both for the overall card and for individual groups of view. + +| Configuration path | Views to which it refers | +| - | - | +| `view.actions` | All (may be overriden by the below) | +| `event_viewer.actions` | `clip`, `snapshot` | +| `event_gallery.actions` | `clips`, `snapshots` | +| `live.actions` | `live` | +| `image.actions` | `image` | + +If an action is configured for both the whole card (`view.actions`) and a more +specific view (e.g. `live.actions`) then the actions are merged, with the more +specific overriding the less specific (see example below). + +The format for actions is the standard Home Assistant [action +format](https://www.home-assistant.io/lovelace/actions/#tap-action) as well as +the custom [Frigate card action](#frigate-card-action) to trigger card changes. + +### Example + +In this example, double clicking the card in any view will cause the card to go +into fullscreen mode, **except** when the view is `live` in which case the +office lights are toggled. + +```yaml +view: + actions: + double_tap_action: + action: custom:frigate-card-action + frigate_card_action: fullscreen +live: + provider: frigate-jsmpeg + actions: + entity: light.office_main_lights + double_tap_action: + action: toggle +``` ## Menu Modes @@ -536,7 +589,7 @@ This card supports several menu configurations. -### Example YAML Configuration +## Example YAML Configuration A configuration that uses WebRTC for live: @@ -558,7 +611,7 @@ A configuration that shows the latest clip on load, but does not automatically p view_default: clip ``` -### Screenshot: Snapshot / Clip Gallery +## Screenshot: Snapshot / Clip Gallery Full viewing of clips: diff --git a/src/card.ts b/src/card.ts index 8a887bbc..a0501ccf 100644 --- a/src/card.ts +++ b/src/card.ts @@ -12,19 +12,23 @@ import { classMap } from 'lit/directives/class-map.js'; import { styleMap } from 'lit/directives/style-map.js'; import { until } from 'lit/directives/until.js'; import { + ActionConfig, HomeAssistant, LovelaceCardEditor, getLovelace, + handleAction, + hasAction, } from 'custom-card-helpers'; import screenfull from 'screenfull'; import { z } from 'zod'; import { - CardAction, - entitySchema, - frigateCardConfigSchema, + ActionType, GetFrigateCardMenuButtonParameters, RawFrigateCardConfig, + entitySchema, + frigateCardConfigSchema, + Actions, } from './types.js'; import type { BrowseMediaQueryParameters, @@ -38,10 +42,16 @@ import type { import { CARD_VERSION, REPO_URL } from './const.js'; import { FrigateCardElements } from './components/elements.js'; -import { FrigateCardMenu, FRIGATE_BUTTON_MENU_ICON, MENU_HEIGHT } from './components/menu.js'; +import { + FRIGATE_BUTTON_MENU_ICON, + MENU_HEIGHT, + FrigateCardMenu, +} from './components/menu.js'; import { View } from './view.js'; import { + convertActionToFrigateCardCustomAction, createFrigateCardCustomAction, + getActionConfigGivenAction, homeAssistantSignPath, homeAssistantWSRequest, isValidMediaShowInfo, @@ -65,14 +75,15 @@ import cardStyle from './scss/card.scss'; import { ResolvedMediaCache } from './resolved-media.js'; import { BrowseMediaUtil } from './browse-media-util.js'; import { isConfigUpgradeable } from './config-mgmt.js'; +import { actionHandler } from './action-handler-directive.js'; /** A note on media callbacks: * - * We need media elements (e.g.