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