Skip to content

Commit

Permalink
Add support assumed media players (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
Drafteed committed Dec 4, 2023
1 parent 1ed8c58 commit d93edbc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/mediaControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,18 @@ class MiniMediaPlayerMediaControls extends LitElement {
renderPlayButtons() {
const { hide } = this.config;
return html`
${!hide.play_pause ? html`
${!hide.play_pause ? this.player.assumedState ? html`
<ha-icon-button
@click=${e => this.player.play(e)}
.icon=${ICON.PLAY.false}>
<ha-icon .icon=${ICON.PLAY.false}></ha-icon>
</ha-icon-button>
<ha-icon-button
@click=${e => this.player.pause(e)}
.icon=${ICON.PLAY.true}>
<ha-icon .icon=${ICON.PLAY.true}></ha-icon>
</ha-icon-button>
` : html`
<ha-icon-button
@click=${e => this.player.playPause(e)}
.icon=${ICON.PLAY[this.player.isPlaying]}>
Expand Down
12 changes: 12 additions & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export default class MediaPlayerObject {
return (!this.isOff && !this.isUnavailable && !this.idle) || false;
}

get assumedState(): boolean {
return this._attr.assumed_state || false;
}

get shuffle(): boolean {
return this._attr.shuffle || false;
}
Expand Down Expand Up @@ -295,6 +299,14 @@ export default class MediaPlayerObject {
this.callService(e, 'play_media', { ...opts });
}

play(e: MouseEvent): void {
this.callService(e, 'media_play');
}

pause(e: MouseEvent): void {
this.callService(e, 'media_pause');
}

playPause(e: MouseEvent): void {
this.callService(e, 'media_play_pause');
}
Expand Down

0 comments on commit d93edbc

Please sign in to comment.