Add automatic provider detection.
This commit is contained in:
+20
-2
@@ -19,6 +19,8 @@ import {
|
||||
WebRTCConfig,
|
||||
FrigateCardError,
|
||||
LiveOverrides,
|
||||
LiveProvider,
|
||||
frigateCardConfigDefaults,
|
||||
} from '../types.js';
|
||||
import { EmblaOptionsType } from 'embla-carousel';
|
||||
import { HomeAssistant } from 'custom-card-helpers';
|
||||
@@ -503,6 +505,20 @@ export class FrigateCardLiveProvider extends LitElement {
|
||||
@property({ attribute: true, type: Boolean })
|
||||
public disabled = false;
|
||||
|
||||
protected _getResolvedProvider(): LiveProvider {
|
||||
if (this.liveConfig?.provider === 'auto') {
|
||||
if (this.cameraConfig?.webrtc?.entity || this.cameraConfig?.webrtc?.url) {
|
||||
return 'webrtc';
|
||||
} else if (this.cameraConfig?.camera_entity) {
|
||||
return 'frigate';
|
||||
} else if (this.cameraConfig?.camera_name) {
|
||||
return 'frigate-jsmpeg';
|
||||
}
|
||||
return frigateCardConfigDefaults.live.provider;
|
||||
}
|
||||
return this.liveConfig?.provider || frigateCardConfigDefaults.live.provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Master render method.
|
||||
* @returns A rendered template.
|
||||
@@ -512,14 +528,16 @@ export class FrigateCardLiveProvider extends LitElement {
|
||||
return;
|
||||
}
|
||||
|
||||
const provider = this._getResolvedProvider();
|
||||
|
||||
return html`
|
||||
${this.liveConfig.provider == 'frigate'
|
||||
${provider == 'frigate'
|
||||
? html` <frigate-card-live-frigate
|
||||
.hass=${this.hass}
|
||||
.cameraEntity=${this.cameraConfig.camera_entity}
|
||||
>
|
||||
</frigate-card-live-frigate>`
|
||||
: this.liveConfig.provider == 'webrtc'
|
||||
: provider == 'webrtc'
|
||||
? html`<frigate-card-live-webrtc
|
||||
.hass=${this.hass}
|
||||
.cameraConfig=${this.cameraConfig}
|
||||
|
||||
@@ -532,6 +532,7 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
|
||||
|
||||
const liveProviders = {
|
||||
'': '',
|
||||
auto: localize('config.live.providers.auto'),
|
||||
frigate: localize('config.live.providers.frigate'),
|
||||
'frigate-jsmpeg': localize('config.live.providers.frigate-jsmpeg'),
|
||||
webrtc: localize('config.live.providers.webrtc'),
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
"preload": "Preload live view in the background",
|
||||
"provider": "Live view provider",
|
||||
"providers": {
|
||||
"auto": "Automatic",
|
||||
"frigate": "Frigate",
|
||||
"frigate-jsmpeg": "Frigate JSMpeg",
|
||||
"webrtc": "WebRTC"
|
||||
|
||||
+3
-2
@@ -50,7 +50,8 @@ const FRIGATE_MENU_MODES = [
|
||||
'above',
|
||||
'below',
|
||||
] as const;
|
||||
const LIVE_PROVIDERS = ['frigate', 'frigate-jsmpeg', 'webrtc'] as const;
|
||||
const LIVE_PROVIDERS = ['auto', 'frigate', 'frigate-jsmpeg', 'webrtc'] as const;
|
||||
export type LiveProvider = typeof LIVE_PROVIDERS[number];
|
||||
|
||||
export class FrigateCardError extends Error {}
|
||||
|
||||
@@ -445,7 +446,7 @@ export type NextPreviousControlConfig = z.infer<typeof nextPreviousControlConfig
|
||||
* Live view configuration section.
|
||||
*/
|
||||
const liveConfigDefault = {
|
||||
provider: 'frigate' as const,
|
||||
provider: 'auto' as const,
|
||||
preload: false,
|
||||
lazy_load: true,
|
||||
draggable: true,
|
||||
|
||||
Reference in New Issue
Block a user