Merge pull request #596 from felipecrs/switch-to-live
Fallback non-Frigate cameras to supported views
This commit is contained in:
+15
-11
@@ -5,7 +5,7 @@ import {
|
|||||||
LitElement,
|
LitElement,
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
unsafeCSS
|
unsafeCSS,
|
||||||
} from 'lit';
|
} from 'lit';
|
||||||
import { customElement, property, state } from 'lit/decorators.js';
|
import { customElement, property, state } from 'lit/decorators.js';
|
||||||
import { classMap } from 'lit/directives/class-map.js';
|
import { classMap } from 'lit/directives/class-map.js';
|
||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
ConditionState,
|
ConditionState,
|
||||||
conditionStateRequestHandler,
|
conditionStateRequestHandler,
|
||||||
getOverriddenConfig,
|
getOverriddenConfig,
|
||||||
getOverridesByKey
|
getOverridesByKey,
|
||||||
} from './card-condition.js';
|
} from './card-condition.js';
|
||||||
import './components/elements.js';
|
import './components/elements.js';
|
||||||
import { FrigateCardElements } from './components/elements.js';
|
import { FrigateCardElements } from './components/elements.js';
|
||||||
@@ -40,7 +40,7 @@ import {
|
|||||||
CAMERA_BIRDSEYE,
|
CAMERA_BIRDSEYE,
|
||||||
CARD_VERSION,
|
CARD_VERSION,
|
||||||
MEDIA_PLAYER_SUPPORT_BROWSE_MEDIA,
|
MEDIA_PLAYER_SUPPORT_BROWSE_MEDIA,
|
||||||
REPO_URL
|
REPO_URL,
|
||||||
} from './const.js';
|
} from './const.js';
|
||||||
import './editor.js';
|
import './editor.js';
|
||||||
import { localize } from './localize/localize.js';
|
import { localize } from './localize/localize.js';
|
||||||
@@ -63,14 +63,14 @@ import {
|
|||||||
MediaShowInfo,
|
MediaShowInfo,
|
||||||
MenuButton,
|
MenuButton,
|
||||||
Message,
|
Message,
|
||||||
RawFrigateCardConfig
|
RawFrigateCardConfig,
|
||||||
} from './types.js';
|
} from './types.js';
|
||||||
import {
|
import {
|
||||||
convertActionToFrigateCardCustomAction,
|
convertActionToFrigateCardCustomAction,
|
||||||
createFrigateCardCustomAction,
|
createFrigateCardCustomAction,
|
||||||
frigateCardHandleAction,
|
frigateCardHandleAction,
|
||||||
frigateCardHasAction,
|
frigateCardHasAction,
|
||||||
getActionConfigGivenAction
|
getActionConfigGivenAction,
|
||||||
} from './utils/action.js';
|
} from './utils/action.js';
|
||||||
import { contentsChanged } from './utils/basic.js';
|
import { contentsChanged } from './utils/basic.js';
|
||||||
import { getCameraIcon, getCameraID, getCameraTitle } from './utils/camera.js';
|
import { getCameraIcon, getCameraID, getCameraTitle } from './utils/camera.js';
|
||||||
@@ -81,14 +81,14 @@ import {
|
|||||||
homeAssistantSignPath,
|
homeAssistantSignPath,
|
||||||
isHassDifferent,
|
isHassDifferent,
|
||||||
isTriggeredState,
|
isTriggeredState,
|
||||||
sideLoadHomeAssistantElements
|
sideLoadHomeAssistantElements,
|
||||||
} from './utils/ha';
|
} from './utils/ha';
|
||||||
import { getEventID } from './utils/ha/browse-media.js';
|
import { getEventID } from './utils/ha/browse-media.js';
|
||||||
import {
|
import {
|
||||||
ExtendedEntityCache,
|
ExtendedEntityCache,
|
||||||
getAllEntities,
|
getAllEntities,
|
||||||
getExtendedEntities,
|
getExtendedEntities,
|
||||||
getExtendedEntity
|
getExtendedEntity,
|
||||||
} from './utils/ha/entity-registry.js';
|
} from './utils/ha/entity-registry.js';
|
||||||
import { ResolvedMediaCache } from './utils/ha/resolved-media.js';
|
import { ResolvedMediaCache } from './utils/ha/resolved-media.js';
|
||||||
import { supportsFeature } from './utils/ha/update.js';
|
import { supportsFeature } from './utils/ha/update.js';
|
||||||
@@ -1246,12 +1246,16 @@ export class FrigateCard extends LitElement {
|
|||||||
case 'camera_select':
|
case 'camera_select':
|
||||||
const camera = frigateCardAction.camera;
|
const camera = frigateCardAction.camera;
|
||||||
if (this._cameras?.has(camera) && this._view) {
|
if (this._cameras?.has(camera) && this._view) {
|
||||||
|
const targetView =
|
||||||
|
this._getConfig().view.camera_select === 'current'
|
||||||
|
? this._view.view
|
||||||
|
: (this._getConfig().view.camera_select as FrigateCardView);
|
||||||
this._changeView({
|
this._changeView({
|
||||||
view: new View({
|
view: new View({
|
||||||
view:
|
view: this._cameras?.get(camera)?.camera_name
|
||||||
this._getConfig().view.camera_select === 'current'
|
? targetView
|
||||||
? this._view.view
|
: // Fallback to supported views for non-Frigate cameras.
|
||||||
: (this._getConfig().view.camera_select as FrigateCardView),
|
View.selectBestViewForNonFrigateCameras(targetView),
|
||||||
camera: camera,
|
camera: camera,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -35,6 +35,15 @@ export class View {
|
|||||||
this.context = params.context ?? null;
|
this.context = params.context ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects the best view for a non-Frigate camera.
|
||||||
|
* @param view The wanted view.
|
||||||
|
* @returns The closest view supported by the non-Frigate camera.
|
||||||
|
*/
|
||||||
|
public static selectBestViewForNonFrigateCameras(view: FrigateCardView) {
|
||||||
|
return ['timeline', 'image'].includes(view) ? view : 'live';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone a view.
|
* Clone a view.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user