Skip to content

Commit

Permalink
Add grid support to media player card
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Mar 5, 2024
1 parent fd478cc commit f953874
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/cards/media-player-card/media-player-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ registerCustomCard({
});

@customElement(MEDIA_PLAYER_CARD_NAME)
export class MediaPlayerCard extends MushroomBaseCard implements LovelaceCard {
export class MediaPlayerCard
extends MushroomBaseCard<MediaPlayerCardConfig, MediaPlayerEntity>
implements LovelaceCard
{
public static async getConfigElement(): Promise<LovelaceCardEditor> {
await import("./media-player-card-editor");
return document.createElement(MEDIA_PLAYER_CARD_EDITOR_NAME) as LovelaceCardEditor;
Expand All @@ -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 [];
Expand All @@ -95,33 +101,21 @@ export class MediaPlayerCard extends MushroomBaseCard implements LovelaceCard {
return controls;
}

public getCardSize(): number | Promise<number> {
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();
}
}
Expand All @@ -147,7 +141,7 @@ export class MediaPlayerCard extends MushroomBaseCard implements LovelaceCard {
}
}

updateControls() {
updateActiveControls() {
const isActiveControlSupported = this._activeControl
? this._controls.includes(this._activeControl)
: false;
Expand Down

0 comments on commit f953874

Please sign in to comment.