Skip to content

Commit

Permalink
✨ Hide next and prev buttons on unsupported entities (#433)
Browse files Browse the repository at this point in the history
Co-authored-by: Karl Kihlström <mrkihlstrom@gmail.com>
  • Loading branch information
dmamontov and kalkih authored Jan 4, 2021
1 parent b74be47 commit 841a545
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/mediaControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class MiniMediaPlayerMediaControls extends LitElement {
` : html``}
${!hide.controls ? html`
<div class='flex mmp-media-controls__media' ?flow=${this.config.flow || this.break}>
${!hide.prev ? html`
${!hide.prev && this.player.supportsPrev ? html`
<ha-icon-button
@click=${e => this.player.prev(e)}
.icon=${ICON.PREV}>
</ha-icon-button>` : ''}
${this.renderPlayButtons()}
${!hide.next ? html`
${!hide.next && this.player.supportsNext ? html`
<ha-icon-button
@click=${e => this.player.next(e)}
.icon=${ICON.NEXT}>
Expand Down
10 changes: 10 additions & 0 deletions src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ export default class MediaPlayerObject {
&& PROGRESS_PROPS.every(prop => prop in this.attr);
}

get supportsPrev() {
return (this.attr.supported_features | 16) // eslint-disable-line no-bitwise
=== this.attr.supported_features;
}

get supportsNext() {
return (this.attr.supported_features | 32) // eslint-disable-line no-bitwise
=== this.attr.supported_features;
}

get progress() {
return this.position + (Date.now() - new Date(this.updatedAt).getTime()) / 1000.0;
}
Expand Down

0 comments on commit 841a545

Please sign in to comment.