Skip to content

Commit

Permalink
fix: Always play the media target after a HA tab change (#1627)
Browse files Browse the repository at this point in the history
* fix: Always play the media target after a HA tab change

* Formatting
  • Loading branch information
dermotduffy authored Oct 9, 2024
1 parent dbee22c commit 057d07a
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions src/components/live/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,6 @@ export class FrigateCardLiveCarousel extends LitElement {
super.disconnectedCallback();
}

updated(changedProperties: PropertyValues): void {
super.updated(changedProperties);

if (!this._mediaActionsController.hasRoot() && this._refCarousel.value) {
this._mediaActionsController.initialize(this._refCarousel.value);
}
}

protected _getTransitionEffect(): TransitionEffect {
return (
this.overriddenLiveConfig?.transition_effect ??
Expand Down Expand Up @@ -366,23 +358,6 @@ export class FrigateCardLiveCarousel extends LitElement {
}),
});
}

if (changedProps.has('viewManagerEpoch')) {
const view = this.viewManagerEpoch?.manager.getView();
const selectedCameraIndex = this._getSelectedCameraIndex();

if (this.viewFilterCameraID) {
this._mediaActionsController.setTarget(
selectedCameraIndex,
// Camera in this carousel is only selected if the camera from the
// view matches the filtered camera.
view?.camera === this.viewFilterCameraID,
);
} else {
// Carousel is not filtered, so the targeted camera is always selected.
this._mediaActionsController.setTarget(selectedCameraIndex, true);
}
}
}

protected _getPlugins(): EmblaCarouselPlugins {
Expand Down Expand Up @@ -664,6 +639,40 @@ export class FrigateCardLiveCarousel extends LitElement {
`;
}

protected _setMediaTarget(): void {
const view = this.viewManagerEpoch?.manager.getView();
const selectedCameraIndex = this._getSelectedCameraIndex();

if (this.viewFilterCameraID) {
this._mediaActionsController.setTarget(
selectedCameraIndex,
// Camera in this carousel is only selected if the camera from the
// view matches the filtered camera.
view?.camera === this.viewFilterCameraID,
);
} else {
// Carousel is not filtered, so the targeted camera is always selected.
this._mediaActionsController.setTarget(selectedCameraIndex, true);
}
}

public updated(changedProperties: PropertyValues): void {
super.updated(changedProperties);

let initialized = false;
if (!this._mediaActionsController.hasRoot() && this._refCarousel.value) {
this._mediaActionsController.initialize(this._refCarousel.value);
initialized = true;
}

// If the view has changed, or if the media actions controller has just been
// initialized, then call the necessary media action.
// See: https://github.com/dermotduffy/frigate-hass-card/issues/1626
if (initialized || changedProperties.has('viewManagerEpoch')) {
this._setMediaTarget();
}
}

static get styles(): CSSResultGroup {
return unsafeCSS(liveCarouselStyle);
}
Expand Down

0 comments on commit 057d07a

Please sign in to comment.