Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/dialogs/more-info/controls/more-info-media_player.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) {
</paper-listbox>
</paper-dropdown-menu>
</div>
<!-- SOUND MODE PICKER -->
<div class="controls layout horizontal justified">
<template is='dom-if' if='[[!computeHideSelectSoundMode(playerObj)]]'>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move dom-if before the div

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks for the help!

<iron-icon class="source-input" icon="mdi:music-note"></iron-icon>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hass:music-note
we generate our own icon pack now

<paper-dropdown-menu class="flex source-input" dynamic-align label-float label='Sound Mode'>
<paper-listbox slot="dropdown-content" selected="{{soundModeIndex}}">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use attr-for-selected so you don't have to use the index

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how 'attr-for-selected' would work. I just made the method identical to the 'source input dropdown menu' that is already in the file. I tested how it works now, and it is working fine.
I suggest keeping the 'soundModeIndex' as it is now, and someone that knows how 'atrr-for-selected' works can update this later and at the same time change the source input that now also uses 'sourceIndex'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you agree @c727

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just implemented "atrr-for-selected".
Thanks for your help @c727

<template is='dom-repeat' items='[[playerObj.soundModeList]]'>
<paper-item>[[item]]</paper-item>
</template>
</paper-listbox>
</paper-dropdown-menu>
</template>
</div>
<!-- TTS -->
<div hidden\$="[[computeHideTTS(ttsLoaded, playerObj)]]" class="layout horizontal end">
<paper-input id="ttsInput" label="[[localize('ui.card.media_player.text_to_speak')]]" class="flex" value="{{ttsMessage}}" on-keydown="ttsCheckForEnter"></paper-input>
Expand All @@ -122,6 +135,12 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) {
observer: 'handleSourceChanged',
},

soundModeIndex: {
type: Number,
value: 0,
observer: 'handleSoundModeChanged',
},

ttsLoaded: {
type: Boolean,
computed: 'computeTTSLoaded(hass)',
Expand All @@ -144,6 +163,10 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) {
this.sourceIndex = newVal.sourceList.indexOf(newVal.source);
}

if (newVal && newVal.soundModeList !== undefined) {
this.soundModeIndex = newVal.soundModeList.indexOf(newVal.soundMode);
}

if (oldVal) {
setTimeout(() => {
this.fire('iron-resize');
Expand Down Expand Up @@ -182,6 +205,10 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) {
return playerObj.isOff || !playerObj.supportsSelectSource || !playerObj.sourceList;
}

computeHideSelectSoundMode(playerObj) {
return playerObj.isOff || !playerObj.supportsSelectSoundMode || !playerObj.soundModeList;
}

computeHideTTS(ttsLoaded, playerObj) {
return !ttsLoaded || !playerObj.supportsPlayMedia;
}
Expand Down Expand Up @@ -227,6 +254,27 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) {
this.playerObj.selectSource(sourceInput);
}

handleSoundModeChanged(soundModeIndex, soundModeIndexOld) {
// Selected Option will transition to '' before transitioning to new value
if (!this.playerObj
|| !this.playerObj.supportsSelectSoundMode
|| this.playerObj.soundModeList === undefined
|| soundModeIndex < 0
|| soundModeIndex >= this.playerObj.soundModeList
|| soundModeIndexOld === undefined
) {
return;
}

const soundModeInput = this.playerObj.soundModeList[soundModeIndex];

if (soundModeInput === this.playerObj.soundMode) {
return;
}

this.playerObj.selectSoundMode(soundModeInput);
}

handleVolumeTap() {
if (!this.playerObj.supportsVolumeMute) {
return;
Expand Down
16 changes: 16 additions & 0 deletions src/util/hass-media-player-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ export default class MediaPlayerEntity {
return (this._feat & 2048) !== 0;
}

get supportsSelectSoundMode() {
return (this._feat & 65536) !== 0;
}

get supportsPlay() {
return (this._feat & 16384) !== 0;
}
Expand Down Expand Up @@ -140,6 +144,14 @@ export default class MediaPlayerEntity {
return this._attr.source_list;
}

get soundMode() {
return this._attr.sound_mode;
}

get soundModeList() {
return this._attr.sound_mode_list;
}

mediaPlayPause() {
this.callService('media_play_pause');
}
Expand Down Expand Up @@ -195,6 +207,10 @@ export default class MediaPlayerEntity {
this.callService('select_source', { source });
}

selectSoundMode(soundMode) {
this.callService('select_sound_mode', { sound_mode: soundMode });
}

// helper method

callService(service, data = {}) {
Expand Down