Skip to content

Commit

Permalink
Allow per-camera trigger borders.
Browse files Browse the repository at this point in the history
  • Loading branch information
dermotduffy committed Jan 24, 2024
1 parent 64a909e commit 06f2151
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ Scan mode tracks Home Assistant state *changes* -- when the card is first starte
| - | - | - | - |
| `enabled` | `false` | :white_check_mark: | Whether to enable scan mode. |
| `filter_selected_camera` | `false` | :white_check_mark: | If set to `true` will only trigger on the currently selected camera.|
| `show_trigger_status` | `true` | :white_check_mark: | Whether or not the card should show a visual indication that it is triggered (a pulsing border around the card edge). |
| `show_trigger_status` | `true` | :white_check_mark: | Whether or not the `live` view should show a visual indication that it is triggered (a pulsing border around the camera edge). |
| `untrigger_seconds` | `0` | :white_check_mark: | The number of seconds to wait after all entities are inactive before untriggering. |
| `actions` | | :white_check_mark: | The actions to take when scan mode triggers (see below). |

Expand Down
9 changes: 3 additions & 6 deletions src/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,6 @@ class FrigateCard extends LitElement {
const cardStyle = {
'aspect-ratio': this._controller.getStyleManager().getAspectRatioStyle(),
};
const cardClasses = {
triggered:
!!this._controller.getTriggersManager().isTriggered() &&
!!this._config?.view.scan.show_trigger_status,
};
const mainClasses = {
main: true,
'curve-top':
Expand All @@ -264,7 +259,6 @@ class FrigateCard extends LitElement {
hasHold: frigateCardHasAction(actions.hold_action),
hasDoubleClick: frigateCardHasAction(actions.double_tap_action),
})}
class="${classMap(cardClasses)}"
style="${styleMap(cardStyle)}"
@frigate-card:message=${(ev: CustomEvent<Message>) =>
this._controller.getMessageManager().setMessageIfHigherPriority(ev.detail)}
Expand Down Expand Up @@ -313,6 +307,9 @@ class FrigateCard extends LitElement {
?.getEpoch()}
.hide=${!!this._controller.getMessageManager().hasMessage()}
.microphoneStream=${this._controller.getMicrophoneManager()?.getStream()}
.triggeredCameraIDs=${this._config?.view.scan.show_trigger_status
? this._controller.getTriggersManager().getTriggeredCameraIDs()
: undefined}
></frigate-card-views>`}
${
// Keep message rendering to last to show messages that may have been
Expand Down
14 changes: 13 additions & 1 deletion src/components/live/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { localize } from '../../localize/localize.js';
import basicBlockStyle from '../../scss/basic-block.scss';
import liveCarouselStyle from '../../scss/live-carousel.scss';
import liveGridStyle from '../../scss/live-grid.scss';
import liveProviderStyle from '../../scss/live-provider.scss';
import {
ExtendedHomeAssistant,
Expand Down Expand Up @@ -114,6 +115,9 @@ export class FrigateCardLive extends LitElement {
@property({ attribute: false })
public microphoneStream?: MediaStream;

@property({ attribute: false })
public triggeredCameraIDs?: Set<string>;

// Whether or not the live view is currently in the background (i.e. preloaded
// but not visible)
@state()
Expand Down Expand Up @@ -219,6 +223,7 @@ export class FrigateCardLive extends LitElement {
.cardWideConfig=${this.cardWideConfig}
.cameraManager=${this.cameraManager}
.microphoneStream=${this.microphoneStream}
.triggeredCameraIDs=${this.triggeredCameraIDs}
@frigate-card:message=${(ev: CustomEvent<Message>) => {
this._renderKey++;
this._messageReceivedPostRender = true;
Expand Down Expand Up @@ -283,7 +288,12 @@ export class FrigateCardLiveGrid extends LitElement {
@property({ attribute: false })
public microphoneStream?: MediaStream;

@property({ attribute: false })
public triggeredCameraIDs?: Set<string>;

protected _renderCarousel(cameraID?: string): TemplateResult {
const triggeredCameraID = cameraID ?? this.view?.camera;

return html`
<frigate-card-live-carousel
grid-id=${ifDefined(cameraID)}
Expand All @@ -297,6 +307,8 @@ export class FrigateCardLiveGrid extends LitElement {
.cardWideConfig=${this.cardWideConfig}
.cameraManager=${this.cameraManager}
.microphoneStream=${this.microphoneStream}
?triggered=${triggeredCameraID &&
!!this.triggeredCameraIDs?.has(triggeredCameraID)}
>
</frigate-card-live-carousel>
`;
Expand Down Expand Up @@ -351,7 +363,7 @@ export class FrigateCardLiveGrid extends LitElement {
}

static get styles(): CSSResultGroup {
return unsafeCSS(basicBlockStyle);
return unsafeCSS(liveGridStyle);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/thumbnail-carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class FrigateCardThumbnailCarousel extends LitElement {
public fadeThumbnails = false;

protected _thumbnailSlides: TemplateResult[] = [];
protected _plugins = [AutoSize()];

protected willUpdate(changedProps: PropertyValues): void {
if (changedProps.has('config')) {
Expand Down Expand Up @@ -137,7 +138,7 @@ export class FrigateCardThumbnailCarousel extends LitElement {

return html`<frigate-card-carousel
direction=${direction}
.plugins=${[AutoSize()]}
.plugins=${this._plugins}
.selected=${this._getSelectedSlide() ?? 0}
.dragFree=${true}
>
Expand Down
4 changes: 4 additions & 0 deletions src/components/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export class FrigateCardViews extends LitElement {
@property({ attribute: false })
public microphoneStream?: MediaStream;

@property({ attribute: false })
public triggeredCameraIDs?: Set<string>;

protected willUpdate(changedProps: PropertyValues): void {
if (changedProps.has('view') || changedProps.has('config')) {
if (this.view?.is('live') || this._shouldLivePreload()) {
Expand Down Expand Up @@ -239,6 +242,7 @@ export class FrigateCardViews extends LitElement {
.cameraManager=${this.cameraManager}
.cardWideConfig=${this.cardWideConfig}
.microphoneStream=${this.microphoneStream}
.triggeredCameraIDs=${this.triggeredCameraIDs}
class="${classMap(liveClasses)}"
>
</frigate-card-live>
Expand Down
20 changes: 1 addition & 19 deletions src/scss/card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// The standard HA header is 56 pixels tall, so that much off the top (header)
// and bottom (to maintain center), before doing the calculation of
// max-height. This matters on small mobile devices in landscape orientation.
--frigate-card-expand-max-height: calc( ( 100vh - (2 * 56px) ) * 0.85 );
--frigate-card-expand-max-height: calc((100vh - (2 * 56px)) * 0.85);
--frigate-card-expand-max-width: 85vw;
--frigate-card-expand-width: none;
--frigate-card-expand-height: none;
Expand Down Expand Up @@ -52,10 +52,6 @@ div.main {
// Necessary to get Safari to show border-radius correctly.
transform: translateZ(0);

// Include the borders in the sizing (to keep the triggered warning pulse
// visible in fullscreen).
box-sizing: border-box;

// Hide scrollbar: Firefox
scrollbar-width: none;
// Hide scrollbar: IE and Edge
Expand Down Expand Up @@ -112,20 +108,6 @@ ha-card {
position: static;
color: var(--secondary-text-color, white);
}
ha-card.triggered {
@keyframes warning-pulse {
0% {
border: solid 2px rgba(0, 0, 0, 0);
}
50% {
border: solid 2px var(--warning-color);
}
100% {
border: solid 2px rgba(0, 0, 0, 0);
}
}
animation: warning-pulse 5s infinite;
}

/************
* Fullscreen
Expand Down
1 change: 1 addition & 0 deletions src/scss/live-carousel.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
:host {
display: block;
--video-max-height: none;
}

Expand Down
20 changes: 20 additions & 0 deletions src/scss/live-grid.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@use 'basic-block.scss';

@keyframes warning-pulse {
0% {
border: solid 2px var(--frigate-card-triggered-color-1, rgba(0, 0, 0, 0));
}
50% {
border: solid 2px var(--frigate-card-triggered-color-2, var(--warning-color));
}
100% {
border: solid 2px var(--frigate-card-triggered-color-1, rgba(0, 0, 0, 0));
}
}

frigate-card-live-carousel[triggered] {
animation: warning-pulse 5s infinite;
}
frigate-card-live-carousel[selected] {
--frigate-card-triggered-color-1: var(--primary-color);
}

0 comments on commit 06f2151

Please sign in to comment.