refactor: Significantly refactor how conditions work internally (#1886)
- Much improved API cleanliness and testability to allow further extensibility in future - Simplified code in `live` view This technically contains a small change in how overrides work in the `live` view. Since that change is _closer_ to the documentation, and since this is likely to be rarely used, this is not considered a breaking change. Previously, overrides for a given live camera would always render _as if_ that camera was selected, vs was actually selected. Now, overrides will only apply in the live view when the camera is _actually_ selected. If this is an issue for you in practice, lets discuss.
This commit is contained in:
+24
-16
@@ -8,10 +8,8 @@ import {
|
||||
unsafeCSS,
|
||||
} from 'lit';
|
||||
import { customElement, property, state } from 'lit/decorators.js';
|
||||
import {
|
||||
ConditionsManagerEpoch,
|
||||
evaluateConditionViaEvent,
|
||||
} from '../card-controller/conditions-manager.js';
|
||||
import { ConditionsManager } from '../conditions/conditions-manager.js';
|
||||
import { getConditionStateManagerViaEvent } from '../conditions/state-manager-via-event.js';
|
||||
import { dispatchAdvancedCameraCardErrorEvent } from '../components-lib/message/dispatch.js';
|
||||
import {
|
||||
AdvancedCameraCardConditional,
|
||||
@@ -76,13 +74,6 @@ export class AdvancedCameraCardElementsCore extends LitElement {
|
||||
@property({ attribute: false })
|
||||
public elements?: PictureElements;
|
||||
|
||||
/**
|
||||
* Need to ensure card re-renders when conditions change, hence having it as a
|
||||
* property even though it is not currently directly used by this class.
|
||||
*/
|
||||
@property({ attribute: false })
|
||||
public conditionsManagerEpoch?: ConditionsManagerEpoch;
|
||||
|
||||
protected _root: HuiConditionalElement | null = null;
|
||||
|
||||
@property({ attribute: false })
|
||||
@@ -162,9 +153,6 @@ export class AdvancedCameraCardElements extends LitElement {
|
||||
@property({ attribute: false })
|
||||
public hass?: HomeAssistant;
|
||||
|
||||
@property({ attribute: false })
|
||||
public conditionsManagerEpoch?: ConditionsManagerEpoch;
|
||||
|
||||
@property({ attribute: false })
|
||||
public elements: PictureElements;
|
||||
|
||||
@@ -248,7 +236,6 @@ export class AdvancedCameraCardElements extends LitElement {
|
||||
protected render(): TemplateResult {
|
||||
return html`<advanced-camera-card-elements-core
|
||||
.hass=${this.hass}
|
||||
.conditionsManagerEpoch=${this.conditionsManagerEpoch}
|
||||
.elements=${this.elements}
|
||||
>
|
||||
</advanced-camera-card-elements-core>`;
|
||||
@@ -267,6 +254,7 @@ export class AdvancedCameraCardElements extends LitElement {
|
||||
@customElement('advanced-camera-card-conditional')
|
||||
export class AdvancedCameraCardElementsConditional extends LitElement {
|
||||
protected _config?: AdvancedCameraCardConditional;
|
||||
protected _conditionManager: ConditionsManager | null = null;
|
||||
|
||||
// A note on hass as an update mechanism:
|
||||
//
|
||||
@@ -283,6 +271,7 @@ export class AdvancedCameraCardElementsConditional extends LitElement {
|
||||
*/
|
||||
public setConfig(config: AdvancedCameraCardConditional): void {
|
||||
this._config = config;
|
||||
this._createConditionManager();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,13 +292,32 @@ export class AdvancedCameraCardElementsConditional extends LitElement {
|
||||
// this is a transparent 'conditional' element (just like the stock HA
|
||||
// 'conditional' element), it should not have positioning.
|
||||
this.className = '';
|
||||
|
||||
this._createConditionManager();
|
||||
}
|
||||
|
||||
disconnectedCallback(): void {
|
||||
this._conditionManager?.destroy();
|
||||
}
|
||||
|
||||
protected _createConditionManager(): void {
|
||||
const conditionStateManager = getConditionStateManagerViaEvent(this);
|
||||
if (!this._config || !conditionStateManager) {
|
||||
return;
|
||||
}
|
||||
this._conditionManager?.destroy();
|
||||
this._conditionManager = new ConditionsManager(
|
||||
this._config.conditions,
|
||||
conditionStateManager,
|
||||
);
|
||||
this._conditionManager.addListener(() => this.requestUpdate());
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the card.
|
||||
*/
|
||||
protected render(): TemplateResult | void {
|
||||
if (evaluateConditionViaEvent(this, this._config?.conditions)) {
|
||||
if (this._conditionManager?.getEvaluation()?.result) {
|
||||
return html` <advanced-camera-card-elements-core
|
||||
.hass=${this.hass}
|
||||
.elements=${this._config?.elements}
|
||||
|
||||
@@ -11,14 +11,9 @@ import { guard } from 'lit/directives/guard.js';
|
||||
import { createRef, Ref, ref } from 'lit/directives/ref.js';
|
||||
import { CameraManager } from '../../camera-manager/manager.js';
|
||||
import { CameraManagerCameraMetadata } from '../../camera-manager/types.js';
|
||||
import {
|
||||
ConditionsManagerEpoch,
|
||||
getOverriddenConfig,
|
||||
} from '../../card-controller/conditions-manager.js';
|
||||
import { MicrophoneState } from '../../card-controller/types.js';
|
||||
import { ViewManagerEpoch } from '../../card-controller/view/types.js';
|
||||
import { MediaActionsController } from '../../components-lib/media-actions-controller.js';
|
||||
import { dispatchAdvancedCameraCardErrorEvent } from '../../components-lib/message/dispatch.js';
|
||||
import { ZoomSettingsObserved } from '../../components-lib/zoom/types.js';
|
||||
import { handleZoomSettingsObservedEvent } from '../../components-lib/zoom/zoom-view-context.js';
|
||||
import {
|
||||
@@ -26,14 +21,11 @@ import {
|
||||
CardWideConfig,
|
||||
configDefaults,
|
||||
LiveConfig,
|
||||
liveConfigAbsoluteRootSchema,
|
||||
Overrides,
|
||||
TransitionEffect,
|
||||
} from '../../config/types.js';
|
||||
import liveCarouselStyle from '../../scss/live-carousel.scss';
|
||||
import { ExtendedHomeAssistant } from '../../types.js';
|
||||
import { stopEventFromActivatingCardWideActions } from '../../utils/action.js';
|
||||
import { contentsChanged } from '../../utils/basic.js';
|
||||
import { CarouselSelected } from '../../utils/embla/carousel-controller.js';
|
||||
import { AutoLazyLoad } from '../../utils/embla/plugins/auto-lazy-load/auto-lazy-load.js';
|
||||
import AutoMediaLoadedInfo from '../../utils/embla/plugins/auto-media-loaded-info/auto-media-loaded-info.js';
|
||||
@@ -70,16 +62,7 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
public viewManagerEpoch?: ViewManagerEpoch;
|
||||
|
||||
@property({ attribute: false })
|
||||
public nonOverriddenLiveConfig?: LiveConfig;
|
||||
|
||||
@property({ attribute: false })
|
||||
public overriddenLiveConfig?: LiveConfig;
|
||||
|
||||
@property({ attribute: false, hasChanged: contentsChanged })
|
||||
public overrides?: Overrides;
|
||||
|
||||
@property({ attribute: false })
|
||||
public conditionsManagerEpoch?: ConditionsManagerEpoch;
|
||||
public liveConfig?: LiveConfig;
|
||||
|
||||
@property({ attribute: false })
|
||||
public cardWideConfig?: CardWideConfig;
|
||||
@@ -116,10 +99,7 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
}
|
||||
|
||||
protected _getTransitionEffect(): TransitionEffect {
|
||||
return (
|
||||
this.overriddenLiveConfig?.transition_effect ??
|
||||
configDefaults.live.transition_effect
|
||||
);
|
||||
return this.liveConfig?.transition_effect ?? configDefaults.live.transition_effect;
|
||||
}
|
||||
|
||||
protected _getSelectedCameraIndex(): number {
|
||||
@@ -138,29 +118,25 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
}
|
||||
|
||||
protected willUpdate(changedProps: PropertyValues): void {
|
||||
if (
|
||||
changedProps.has('microphoneState') ||
|
||||
changedProps.has('overriddenLiveConfig')
|
||||
) {
|
||||
if (changedProps.has('microphoneState') || changedProps.has('liveConfig')) {
|
||||
this._mediaActionsController.setOptions({
|
||||
playerSelector: ADVANCED_CAMERA_CARD_LIVE_PROVIDER,
|
||||
...(this.overriddenLiveConfig?.auto_play && {
|
||||
autoPlayConditions: this.overriddenLiveConfig.auto_play,
|
||||
...(this.liveConfig?.auto_play && {
|
||||
autoPlayConditions: this.liveConfig.auto_play,
|
||||
}),
|
||||
...(this.overriddenLiveConfig?.auto_pause && {
|
||||
autoPauseConditions: this.overriddenLiveConfig.auto_pause,
|
||||
...(this.liveConfig?.auto_pause && {
|
||||
autoPauseConditions: this.liveConfig.auto_pause,
|
||||
}),
|
||||
...(this.overriddenLiveConfig?.auto_mute && {
|
||||
autoMuteConditions: this.overriddenLiveConfig.auto_mute,
|
||||
...(this.liveConfig?.auto_mute && {
|
||||
autoMuteConditions: this.liveConfig.auto_mute,
|
||||
}),
|
||||
...(this.overriddenLiveConfig?.auto_unmute && {
|
||||
autoUnmuteConditions: this.overriddenLiveConfig.auto_unmute,
|
||||
...(this.liveConfig?.auto_unmute && {
|
||||
autoUnmuteConditions: this.liveConfig.auto_unmute,
|
||||
}),
|
||||
...((this.overriddenLiveConfig?.auto_unmute ||
|
||||
this.overriddenLiveConfig?.auto_mute) && {
|
||||
...((this.liveConfig?.auto_unmute || this.liveConfig?.auto_mute) && {
|
||||
microphoneState: this.microphoneState,
|
||||
microphoneMuteSeconds:
|
||||
this.overriddenLiveConfig.microphone.mute_after_microphone_mute_seconds,
|
||||
this.liveConfig.microphone.mute_after_microphone_mute_seconds,
|
||||
}),
|
||||
});
|
||||
}
|
||||
@@ -169,11 +145,11 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
protected _getPlugins(): EmblaCarouselPlugins {
|
||||
return [
|
||||
AutoLazyLoad({
|
||||
...(this.overriddenLiveConfig?.lazy_load && {
|
||||
...(this.liveConfig?.lazy_load && {
|
||||
lazyLoadCallback: (index, slide) =>
|
||||
this._lazyloadOrUnloadSlide('load', index, slide),
|
||||
}),
|
||||
lazyUnloadConditions: this.overriddenLiveConfig?.lazy_unload,
|
||||
lazyUnloadConditions: this.liveConfig?.lazy_unload,
|
||||
lazyUnloadCallback: (index, slide) =>
|
||||
this._lazyloadOrUnloadSlide('unload', index, slide),
|
||||
}),
|
||||
@@ -191,7 +167,7 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
*/
|
||||
protected _getLazyLoadCount(): number | null {
|
||||
// Defaults to fully-lazy loading.
|
||||
return this.overriddenLiveConfig?.lazy_load === false ? null : 0;
|
||||
return this.liveConfig?.lazy_load === false ? null : 0;
|
||||
}
|
||||
|
||||
protected _getSlides(): [TemplateResult[], Record<string, number>] {
|
||||
@@ -265,43 +241,17 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
cameraID: string,
|
||||
cameraConfig: CameraConfig,
|
||||
): TemplateResult | void {
|
||||
if (
|
||||
!this.overriddenLiveConfig ||
|
||||
!this.nonOverriddenLiveConfig ||
|
||||
!this.hass ||
|
||||
!this.cameraManager ||
|
||||
!this.conditionsManagerEpoch
|
||||
) {
|
||||
if (!this.liveConfig || !this.hass || !this.cameraManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
let liveConfig: LiveConfig | null = null;
|
||||
|
||||
try {
|
||||
// The condition controller object contains the currently live camera, which
|
||||
// (in the carousel for example) is not necessarily the live camera *this*
|
||||
// <advanced-camera-card-live-provider> is rendering right now, so we provide a
|
||||
// stateOverride to evaluate the condition in that context.
|
||||
liveConfig = getOverriddenConfig(
|
||||
this.conditionsManagerEpoch.manager,
|
||||
{ live: this.nonOverriddenLiveConfig },
|
||||
{
|
||||
configOverrides: this.overrides,
|
||||
stateOverrides: { camera: cameraID },
|
||||
schema: liveConfigAbsoluteRootSchema,
|
||||
},
|
||||
).live;
|
||||
} catch (ev) {
|
||||
return dispatchAdvancedCameraCardErrorEvent(this, ev);
|
||||
}
|
||||
|
||||
const cameraMetadata = this.cameraManager.getCameraMetadata(cameraID);
|
||||
const view = this.viewManagerEpoch?.manager.getView();
|
||||
|
||||
return html`
|
||||
<div class="embla__slide">
|
||||
<advanced-camera-card-live-provider
|
||||
?load=${!liveConfig.lazy_load}
|
||||
?load=${!this.liveConfig.lazy_load}
|
||||
.microphoneState=${view?.camera === cameraID
|
||||
? this.microphoneState
|
||||
: undefined}
|
||||
@@ -311,7 +261,7 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
() => this.cameraManager?.getCameraEndpoints(cameraID) ?? undefined,
|
||||
)}
|
||||
.label=${cameraMetadata?.title ?? ''}
|
||||
.liveConfig=${liveConfig}
|
||||
.liveConfig=${this.liveConfig}
|
||||
.hass=${this.hass}
|
||||
.cardWideConfig=${this.cardWideConfig}
|
||||
.zoomSettings=${view?.context?.zoom?.[cameraID]?.requested}
|
||||
@@ -385,7 +335,7 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
slot=${side}
|
||||
.hass=${this.hass}
|
||||
.side=${side}
|
||||
.controlConfig=${this.overriddenLiveConfig?.controls.next_previous}
|
||||
.controlConfig=${this.liveConfig?.controls.next_previous}
|
||||
.label=${neighbor?.metadata?.title ?? ''}
|
||||
.icon=${neighbor?.metadata?.icon}
|
||||
?disabled=${!neighbor}
|
||||
@@ -399,7 +349,7 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
|
||||
protected render(): TemplateResult | void {
|
||||
const view = this.viewManagerEpoch?.manager.getView();
|
||||
if (!this.overriddenLiveConfig || !this.hass || !view || !this.cameraManager) {
|
||||
if (!this.liveConfig || !this.hass || !view || !this.cameraManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -427,9 +377,9 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
<advanced-camera-card-carousel
|
||||
${ref(this._refCarousel)}
|
||||
.loop=${hasMultipleCameras}
|
||||
.dragEnabled=${hasMultipleCameras && this.overriddenLiveConfig?.draggable}
|
||||
.dragEnabled=${hasMultipleCameras && this.liveConfig?.draggable}
|
||||
.plugins=${guard(
|
||||
[this.cameraManager, this.overriddenLiveConfig],
|
||||
[this.cameraManager, this.liveConfig],
|
||||
this._getPlugins.bind(this),
|
||||
)}
|
||||
.selected=${this._getSelectedCameraIndex()}
|
||||
@@ -449,7 +399,7 @@ export class AdvancedCameraCardLiveCarousel extends LitElement {
|
||||
${this._renderNextPrevious('right', neighbors)}
|
||||
</advanced-camera-card-carousel>
|
||||
<advanced-camera-card-ptz
|
||||
.config=${this.overriddenLiveConfig.controls.ptz}
|
||||
.config=${this.liveConfig.controls.ptz}
|
||||
.cameraManager=${this.cameraManager}
|
||||
.cameraID=${getStreamCameraID(view, this.viewFilterCameraID)}
|
||||
.forceVisibility=${forcePTZVisibility}
|
||||
|
||||
@@ -9,14 +9,12 @@ import {
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import { ifDefined } from 'lit/directives/if-defined.js';
|
||||
import { CameraManager } from '../../camera-manager/manager.js';
|
||||
import { ConditionsManagerEpoch } from '../../card-controller/conditions-manager.js';
|
||||
import { MicrophoneState } from '../../card-controller/types.js';
|
||||
import { ViewManagerEpoch } from '../../card-controller/view/types.js';
|
||||
import { MediaGridSelected } from '../../components-lib/media-grid-controller.js';
|
||||
import { CardWideConfig, LiveConfig, Overrides } from '../../config/types.js';
|
||||
import { CardWideConfig, LiveConfig } from '../../config/types.js';
|
||||
import liveGridStyle from '../../scss/live-grid.scss';
|
||||
import { ExtendedHomeAssistant } from '../../types.js';
|
||||
import { contentsChanged } from '../../utils/basic.js';
|
||||
import './carousel.js';
|
||||
|
||||
@customElement('advanced-camera-card-live-grid')
|
||||
@@ -28,16 +26,7 @@ export class AdvancedCameraCardLiveGrid extends LitElement {
|
||||
public viewManagerEpoch?: ViewManagerEpoch;
|
||||
|
||||
@property({ attribute: false })
|
||||
public nonOverriddenLiveConfig?: LiveConfig;
|
||||
|
||||
@property({ attribute: false })
|
||||
public overriddenLiveConfig?: LiveConfig;
|
||||
|
||||
@property({ attribute: false, hasChanged: contentsChanged })
|
||||
public overrides?: Overrides;
|
||||
|
||||
@property({ attribute: false })
|
||||
public conditionsManagerEpoch?: ConditionsManagerEpoch;
|
||||
public liveConfig?: LiveConfig;
|
||||
|
||||
@property({ attribute: false })
|
||||
public cardWideConfig?: CardWideConfig;
|
||||
@@ -61,10 +50,7 @@ export class AdvancedCameraCardLiveGrid extends LitElement {
|
||||
.hass=${this.hass}
|
||||
.viewManagerEpoch=${this.viewManagerEpoch}
|
||||
.viewFilterCameraID=${cameraID}
|
||||
.nonOverriddenLiveConfig=${this.nonOverriddenLiveConfig}
|
||||
.overriddenLiveConfig=${this.overriddenLiveConfig}
|
||||
.conditionsManagerEpoch=${this.conditionsManagerEpoch}
|
||||
.overrides=${this.overrides}
|
||||
.liveConfig=${this.liveConfig}
|
||||
.cardWideConfig=${this.cardWideConfig}
|
||||
.cameraManager=${this.cameraManager}
|
||||
.microphoneState=${this.microphoneState}
|
||||
@@ -101,9 +87,6 @@ export class AdvancedCameraCardLiveGrid extends LitElement {
|
||||
}
|
||||
|
||||
protected render(): TemplateResult | void {
|
||||
if (!this.conditionsManagerEpoch || !this.nonOverriddenLiveConfig) {
|
||||
return;
|
||||
}
|
||||
const cameraIDs = this.cameraManager?.getStore().getCameraIDsWithCapability('live');
|
||||
if (!cameraIDs?.size || !this._needsGrid()) {
|
||||
return this._renderCarousel();
|
||||
@@ -112,7 +95,7 @@ export class AdvancedCameraCardLiveGrid extends LitElement {
|
||||
return html`
|
||||
<advanced-camera-card-media-grid
|
||||
.selected=${this.viewManagerEpoch?.manager.getView()?.camera}
|
||||
.displayConfig=${this.overriddenLiveConfig?.display}
|
||||
.displayConfig=${this.liveConfig?.display}
|
||||
@advanced-camera-card:media-grid:selected=${(
|
||||
ev: CustomEvent<MediaGridSelected>,
|
||||
) => this._gridSelectCamera(ev.detail.selected)}
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
import { CSSResultGroup, html, LitElement, TemplateResult, unsafeCSS } from 'lit';
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import { CameraManager } from '../../camera-manager/manager.js';
|
||||
import { ConditionsManagerEpoch } from '../../card-controller/conditions-manager.js';
|
||||
import { MicrophoneState } from '../../card-controller/types.js';
|
||||
import { ViewManagerEpoch } from '../../card-controller/view/types.js';
|
||||
import { LiveController } from '../../components-lib/live/live-controller.js';
|
||||
import { CardWideConfig, LiveConfig, Overrides } from '../../config/types.js';
|
||||
import { CardWideConfig, LiveConfig } from '../../config/types.js';
|
||||
import basicBlockStyle from '../../scss/basic-block.scss';
|
||||
import { ExtendedHomeAssistant } from '../../types.js';
|
||||
import { contentsChanged } from '../../utils/basic.js';
|
||||
import './grid.js';
|
||||
|
||||
@customElement('advanced-camera-card-live')
|
||||
export class AdvancedCameraCardLive extends LitElement {
|
||||
@property({ attribute: false })
|
||||
public conditionsManagerEpoch?: ConditionsManagerEpoch;
|
||||
|
||||
@property({ attribute: false })
|
||||
public hass?: ExtendedHomeAssistant;
|
||||
|
||||
@@ -23,13 +18,7 @@ export class AdvancedCameraCardLive extends LitElement {
|
||||
public viewManagerEpoch?: ViewManagerEpoch;
|
||||
|
||||
@property({ attribute: false })
|
||||
public nonOverriddenLiveConfig?: LiveConfig;
|
||||
|
||||
@property({ attribute: false })
|
||||
public overriddenLiveConfig?: LiveConfig;
|
||||
|
||||
@property({ attribute: false, hasChanged: contentsChanged })
|
||||
public overrides?: Overrides;
|
||||
public liveConfig?: LiveConfig;
|
||||
|
||||
@property({ attribute: false })
|
||||
public cameraManager?: CameraManager;
|
||||
@@ -46,7 +35,7 @@ export class AdvancedCameraCardLive extends LitElement {
|
||||
protected _controller = new LiveController(this);
|
||||
|
||||
protected render(): TemplateResult | void {
|
||||
if (!this.hass || !this.nonOverriddenLiveConfig || !this.cameraManager) {
|
||||
if (!this.hass || !this.cameraManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,11 +49,8 @@ export class AdvancedCameraCardLive extends LitElement {
|
||||
<advanced-camera-card-live-grid
|
||||
.hass=${this.hass}
|
||||
.viewManagerEpoch=${this.viewManagerEpoch}
|
||||
.nonOverriddenLiveConfig=${this.nonOverriddenLiveConfig}
|
||||
.overriddenLiveConfig=${this.overriddenLiveConfig}
|
||||
.liveConfig=${this.liveConfig}
|
||||
.inBackground=${this._controller.isInBackground()}
|
||||
.conditionsManagerEpoch=${this.conditionsManagerEpoch}
|
||||
.overrides=${this.overrides}
|
||||
.cardWideConfig=${this.cardWideConfig}
|
||||
.cameraManager=${this.cameraManager}
|
||||
.microphoneState=${this.microphoneState}
|
||||
|
||||
@@ -25,8 +25,8 @@ import { STREAM_TROUBLESHOOTING_URL } from '../../const.js';
|
||||
import { localize } from '../../localize/localize.js';
|
||||
import liveProviderStyle from '../../scss/live-provider.scss';
|
||||
import {
|
||||
ExtendedHomeAssistant,
|
||||
AdvancedCameraCardMediaPlayer,
|
||||
ExtendedHomeAssistant,
|
||||
FullscreenElement,
|
||||
} from '../../types.js';
|
||||
import { aspectRatioToString } from '../../utils/basic.js';
|
||||
@@ -210,6 +210,7 @@ export class AdvancedCameraCardLiveProvider
|
||||
dispatchMediaUnloadedEvent(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (changedProps.has('liveConfig')) {
|
||||
if (this.liveConfig?.show_image_during_load) {
|
||||
this._importPromises.push(import('./providers/image.js'));
|
||||
|
||||
+15
-53
@@ -9,7 +9,6 @@ import {
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import { CameraManager } from '../camera-manager/manager.js';
|
||||
import { ConditionsManagerEpoch } from '../card-controller/conditions-manager.js';
|
||||
import { MicrophoneState } from '../card-controller/types.js';
|
||||
import { ViewManagerEpoch } from '../card-controller/view/types.js';
|
||||
import {
|
||||
@@ -39,10 +38,7 @@ export class AdvancedCameraCardViews extends LitElement {
|
||||
public cameraManager?: CameraManager;
|
||||
|
||||
@property({ attribute: false })
|
||||
public nonOverriddenConfig?: AdvancedCameraCardConfig;
|
||||
|
||||
@property({ attribute: false })
|
||||
public overriddenConfig?: AdvancedCameraCardConfig;
|
||||
public config?: AdvancedCameraCardConfig;
|
||||
|
||||
@property({ attribute: false })
|
||||
public cardWideConfig?: CardWideConfig;
|
||||
@@ -53,9 +49,6 @@ export class AdvancedCameraCardViews extends LitElement {
|
||||
@property({ attribute: false })
|
||||
public resolvedMediaCache?: ResolvedMediaCache;
|
||||
|
||||
@property({ attribute: false })
|
||||
public conditionsManagerEpoch?: ConditionsManagerEpoch;
|
||||
|
||||
@property({ attribute: false })
|
||||
public hide?: boolean;
|
||||
|
||||
@@ -94,31 +87,12 @@ export class AdvancedCameraCardViews extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
protected shouldUpdate(_: PropertyValues): boolean {
|
||||
// Future: Updates to `hass` and `conditionState` here will be frequent.
|
||||
// Throttling here may be necessary if users report performance degradation
|
||||
// > v5.0.0-beta1 .
|
||||
//
|
||||
// These updates are necessary in these cases:
|
||||
// - conditionState: Required to let `advanced-camera-card-live` calculate its own
|
||||
// overrides.
|
||||
// - hass: Required for anything that needs to sign URLs. Of note is
|
||||
// anything that renders an image (e.g. a thumbnail -- almost everything,
|
||||
// or the main `advanced-camera-card-image` view).
|
||||
//
|
||||
// It should instead be possible to pass conditionState to live only (every
|
||||
// update required), and pass hass only once / 5 minutes (see
|
||||
// HASS_REJECTION_CUTOFF_MS).
|
||||
return true;
|
||||
}
|
||||
|
||||
protected _shouldLivePreload(): boolean {
|
||||
const view = this.viewManagerEpoch?.manager.getView();
|
||||
return (
|
||||
// Special case: Never preload for diagnostics -- we want that to be as
|
||||
// minimal as possible.
|
||||
!!this.overriddenConfig?.live.preload && !view?.is('diagnostics')
|
||||
!!this.config?.live.preload && !view?.is('diagnostics')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -127,12 +101,7 @@ export class AdvancedCameraCardViews extends LitElement {
|
||||
// overall views pane to render in ~almost all cases (e.g. for a camera
|
||||
// initialization error to display, `view` and `cameraConfig` may both be
|
||||
// undefined, but we still want to render).
|
||||
if (
|
||||
!this.hass ||
|
||||
!this.overriddenConfig ||
|
||||
!this.nonOverriddenConfig ||
|
||||
!this.cardWideConfig
|
||||
) {
|
||||
if (!this.hass || !this.config || !this.cardWideConfig) {
|
||||
return html``;
|
||||
}
|
||||
|
||||
@@ -148,17 +117,17 @@ export class AdvancedCameraCardViews extends LitElement {
|
||||
};
|
||||
|
||||
const thumbnailConfig = view?.is('live')
|
||||
? this.overriddenConfig.live.controls.thumbnails
|
||||
? this.config.live.controls.thumbnails
|
||||
: view?.isViewerView()
|
||||
? this.overriddenConfig.media_viewer.controls.thumbnails
|
||||
? this.config.media_viewer.controls.thumbnails
|
||||
: view?.is('timeline')
|
||||
? this.overriddenConfig.timeline.controls.thumbnails
|
||||
? this.config.timeline.controls.thumbnails
|
||||
: undefined;
|
||||
|
||||
const miniTimelineConfig = view?.is('live')
|
||||
? this.overriddenConfig.live.controls.timeline
|
||||
? this.config.live.controls.timeline
|
||||
: view?.isViewerView()
|
||||
? this.overriddenConfig.media_viewer.controls.timeline
|
||||
? this.config.media_viewer.controls.timeline
|
||||
: undefined;
|
||||
|
||||
const cameraConfig = view
|
||||
@@ -176,7 +145,7 @@ export class AdvancedCameraCardViews extends LitElement {
|
||||
>
|
||||
${!this.hide && view?.is('image') && cameraConfig
|
||||
? html` <advanced-camera-card-image
|
||||
.imageConfig=${this.overriddenConfig.image}
|
||||
.imageConfig=${this.config.image}
|
||||
.viewManagerEpoch=${this.viewManagerEpoch}
|
||||
.hass=${this.hass}
|
||||
.cameraConfig=${cameraConfig}
|
||||
@@ -188,7 +157,7 @@ export class AdvancedCameraCardViews extends LitElement {
|
||||
? html` <advanced-camera-card-gallery
|
||||
.hass=${this.hass}
|
||||
.viewManagerEpoch=${this.viewManagerEpoch}
|
||||
.galleryConfig=${this.overriddenConfig.media_gallery}
|
||||
.galleryConfig=${this.config.media_gallery}
|
||||
.cameraManager=${this.cameraManager}
|
||||
.cardWideConfig=${this.cardWideConfig}
|
||||
>
|
||||
@@ -199,7 +168,7 @@ export class AdvancedCameraCardViews extends LitElement {
|
||||
<advanced-camera-card-viewer
|
||||
.hass=${this.hass}
|
||||
.viewManagerEpoch=${this.viewManagerEpoch}
|
||||
.viewerConfig=${this.overriddenConfig.media_viewer}
|
||||
.viewerConfig=${this.config.media_viewer}
|
||||
.resolvedMediaCache=${this.resolvedMediaCache}
|
||||
.cameraManager=${this.cameraManager}
|
||||
.cardWideConfig=${this.cardWideConfig}
|
||||
@@ -211,7 +180,7 @@ export class AdvancedCameraCardViews extends LitElement {
|
||||
? html` <advanced-camera-card-timeline
|
||||
.hass=${this.hass}
|
||||
.viewManagerEpoch=${this.viewManagerEpoch}
|
||||
.timelineConfig=${this.overriddenConfig.timeline}
|
||||
.timelineConfig=${this.config.timeline}
|
||||
.cameraManager=${this.cameraManager}
|
||||
.cardWideConfig=${this.cardWideConfig}
|
||||
>
|
||||
@@ -226,21 +195,14 @@ export class AdvancedCameraCardViews extends LitElement {
|
||||
</advanced-camera-card-diagnostics>`
|
||||
: ``}
|
||||
${
|
||||
// Note: Subtle difference in condition below vs the other views in order
|
||||
// to always render the live view for live.preload mode.
|
||||
|
||||
// Note: <advanced-camera-card-live> uses nonOverriddenConfig rather than the
|
||||
// overriden config as it does it's own overriding as part of the camera
|
||||
// carousel.
|
||||
// Note: Subtle difference in condition below vs the other views in
|
||||
// order to always render the live view for live.preload mode.
|
||||
this._shouldLivePreload() || (!this.hide && view?.is('live'))
|
||||
? html`
|
||||
<advanced-camera-card-live
|
||||
.hass=${this.hass}
|
||||
.viewManagerEpoch=${this.viewManagerEpoch}
|
||||
.nonOverriddenLiveConfig=${this.nonOverriddenConfig.live}
|
||||
.overriddenLiveConfig=${this.overriddenConfig.live}
|
||||
.conditionsManagerEpoch=${this.conditionsManagerEpoch}
|
||||
.overrides=${this.overriddenConfig.overrides}
|
||||
.liveConfig=${this.config.live}
|
||||
.cameraManager=${this.cameraManager}
|
||||
.cardWideConfig=${this.cardWideConfig}
|
||||
.microphoneState=${this.microphoneState}
|
||||
|
||||
Reference in New Issue
Block a user