Add tooltip to live camera view.

This commit is contained in:
Dermot Duffy
2022-01-14 21:31:16 -08:00
parent 4a93d02fe9
commit 38cddd0f18
3 changed files with 24 additions and 26 deletions
+12
View File
@@ -6,6 +6,7 @@ import { ZodSchema, z } from 'zod';
import { localize } from './localize/localize.js'; import { localize } from './localize/localize.js';
import { import {
ActionType, ActionType,
CameraConfig,
ExtendedHomeAssistant, ExtendedHomeAssistant,
FrigateCardAction, FrigateCardAction,
FrigateCardCustomAction, FrigateCardCustomAction,
@@ -395,3 +396,14 @@ export function refreshDynamicStateParameters(
params.icon = params.icon ?? stateIcon(state); params.icon = params.icon ?? stateIcon(state);
return params; return params;
} }
export function refreshCameraConfigDynamicParameters(
hass: HomeAssistant,
config: CameraConfig): CameraConfig {
if (hass && config.camera_entity) {
const state = hass.states[config.camera_entity];
config.title = config.title ?? (state?.attributes?.friendly_name || config.camera_entity);
config.icon = config.icon ?? stateIcon(state);
}
return config;
}
+12 -23
View File
@@ -36,7 +36,7 @@ import {
dispatchPauseEvent, dispatchPauseEvent,
dispatchPlayEvent, dispatchPlayEvent,
homeAssistantSignPath, homeAssistantSignPath,
refreshDynamicStateParameters, refreshCameraConfigDynamicParameters,
} from '../common.js'; } from '../common.js';
import { renderProgressIndicator } from '../components/message.js'; import { renderProgressIndicator } from '../components/message.js';
@@ -238,9 +238,13 @@ export class FrigateCardLiveCarousel extends FrigateCardMediaCarousel {
if (!this.cameras) { if (!this.cameras) {
return []; return [];
} }
return Array.from(this.cameras.values()).map((cameraConfig, index) => return Array.from(this.cameras.values()).map((cameraConfig, index) => {
this._renderLive(cameraConfig, index), let refreshedConfig = {...cameraConfig};
); if (this.hass) {
refreshedConfig = refreshCameraConfigDynamicParameters(this.hass, refreshedConfig);
}
return this._renderLive(refreshedConfig, index)
});
} }
/** /**
@@ -271,10 +275,11 @@ export class FrigateCardLiveCarousel extends FrigateCardMediaCarousel {
protected _renderLive(cameraConfig: CameraConfig, slideIndex: number): TemplateResult { protected _renderLive(cameraConfig: CameraConfig, slideIndex: number): TemplateResult {
return html` <div class="embla__slide"> return html` <div class="embla__slide">
<frigate-card-live-provider <frigate-card-live-provider
.title=${cameraConfig.title ?? ''}
.hass=${this.hass} .hass=${this.hass}
.cameraConfig=${cameraConfig} .cameraConfig=${cameraConfig}
.liveConfig=${this.liveConfig} .liveConfig=${this.liveConfig}
?lazyLoad=${this._getLazyLoadCount() != null} ?disabled=${this._getLazyLoadCount() != null}
@frigate-card:media-show=${(e: CustomEvent<MediaShowInfo>) => @frigate-card:media-show=${(e: CustomEvent<MediaShowInfo>) =>
this._mediaShowEventHandler(slideIndex, e)} this._mediaShowEventHandler(slideIndex, e)}
> >
@@ -293,34 +298,18 @@ export class FrigateCardLiveCarousel extends FrigateCardMediaCarousel {
return [null, null]; return [null, null];
} }
const getDynamicParameters = (config: CameraConfig): CameraConfig | null => {
if (!this.hass) {
return null;
}
const stateParameters = refreshDynamicStateParameters(this.hass, {
entity: config.camera_entity,
title: config.title,
icon: config.icon,
});
return {
...config,
title: stateParameters.title ?? undefined,
icon: stateParameters.icon,
};
};
let prev: CameraConfig | null = null, let prev: CameraConfig | null = null,
next: CameraConfig | null = null; next: CameraConfig | null = null;
if (currentIndex > 0) { if (currentIndex > 0) {
prev = this.cameras.get(keys[currentIndex - 1]) ?? null; prev = this.cameras.get(keys[currentIndex - 1]) ?? null;
if (prev) { if (prev) {
prev = getDynamicParameters(prev); prev = refreshCameraConfigDynamicParameters(this.hass, {...prev});
} }
} }
if (currentIndex + 1 < this.cameras.size) { if (currentIndex + 1 < this.cameras.size) {
next = this.cameras.get(keys[currentIndex + 1]) ?? null; next = this.cameras.get(keys[currentIndex + 1]) ?? null;
if (next) { if (next) {
next = getDynamicParameters(next); next = refreshCameraConfigDynamicParameters(this.hass, {...next});
} }
} }
return [prev, next]; return [prev, next];
-3
View File
@@ -8,9 +8,6 @@ import controlStyle from '../scss/next-previous-control.scss';
@customElement('frigate-card-next-previous-control') @customElement('frigate-card-next-previous-control')
export class FrigateCardNextPreviousControl extends LitElement { export class FrigateCardNextPreviousControl extends LitElement {
@property({ attribute: true })
public title = '';
@property({ attribute: false }) @property({ attribute: false })
public direction?: 'next' | 'previous'; public direction?: 'next' | 'previous';