From f95387453e1a75b4e8d462074039e84e23ceb4c7 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Tue, 5 Mar 2024 15:21:55 +0100 Subject: [PATCH] Add grid support to media player card --- .../media-player-card/media-player-card.ts | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/cards/media-player-card/media-player-card.ts b/src/cards/media-player-card/media-player-card.ts index 12c8183c..89a6459f 100644 --- a/src/cards/media-player-card/media-player-card.ts +++ b/src/cards/media-player-card/media-player-card.ts @@ -55,7 +55,10 @@ registerCustomCard({ }); @customElement(MEDIA_PLAYER_CARD_NAME) -export class MediaPlayerCard extends MushroomBaseCard implements LovelaceCard { +export class MediaPlayerCard + extends MushroomBaseCard + implements LovelaceCard +{ public static async getConfigElement(): Promise { await import("./media-player-card-editor"); return document.createElement(MEDIA_PLAYER_CARD_EDITOR_NAME) as LovelaceCardEditor; @@ -72,11 +75,14 @@ export class MediaPlayerCard extends MushroomBaseCard implements LovelaceCard { }; } - @state() private _config?: MediaPlayerCardConfig; - @state() private _activeControl?: MediaPlayerCardControl; - @state() private _inGrid = false; + protected get hasControls(): boolean { + return ( + Boolean(this._config?.media_controls?.length) || + Boolean(this._config?.volume_controls?.length) + ); + } private get _controls(): MediaPlayerCardControl[] { if (!this._config || !this.hass || !this._config.entity) return []; @@ -95,33 +101,21 @@ export class MediaPlayerCard extends MushroomBaseCard implements LovelaceCard { return controls; } - public getCardSize(): number | Promise { - return 1; - } - _onControlTap(ctrl, e): void { e.stopPropagation(); this._activeControl = ctrl; } setConfig(config: MediaPlayerCardConfig): void { - this._config = { - tap_action: { - action: "more-info", - }, - hold_action: { - action: "more-info", - }, - ...config, - }; - this.updateControls(); + super.setConfig(config); + this.updateActiveControls(); this.updateVolume(); } protected updated(changedProperties: PropertyValues) { super.updated(changedProperties); if (this.hass && changedProperties.has("hass")) { - this.updateControls(); + this.updateActiveControls(); this.updateVolume(); } } @@ -147,7 +141,7 @@ export class MediaPlayerCard extends MushroomBaseCard implements LovelaceCard { } } - updateControls() { + updateActiveControls() { const isActiveControlSupported = this._activeControl ? this._controls.includes(this._activeControl) : false;