Skip to content
Closed
Changes from 3 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
59 changes: 59 additions & 0 deletions src/more-infos/more-info-media_player.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@
</paper-listbox>
</paper-dropdown-menu>
</div>
<!-- SOUND MODE PICKER -->
<div class='controls layout horizontal justified'
hidden$='[[computeHideSelectSoundMode(isOff, supportsSelectSoundMode)]]'>

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.

dom-if it instead

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 don't know exactly what you mean but I guess you mean to use a "dom-if" property in the

instead of using the hidden$.
Again I am not an expert in how this works and what the diffrence is.
But the rest of the file is using the hidden$ property.

Basically I made a copy of the Source input, so everything is done in a similar way as the already implemented Source input.

Would it not be better to keep everything the same as the rest of the file for now.
Maybe someone else who does no what the diffrence is and nows how to use these properties correctly can change it for the whole file at once (also for the SourceInput, Power and Volume).

<iron-icon class="source-input" icon="mdi:music-note"></iron-icon>
<paper-dropdown-menu class="flex source-input" dynamic-align label-float label='Sound Mode'>
<paper-listbox slot="dropdown-content" selected="{{soundModeIndex}}">
<template is='dom-repeat' items='[[stateObj.attributes.sound_mode_list]]'>
<paper-item>[[item]]</paper-item>
</template>
</paper-listbox>
</paper-dropdown-menu>
</div>
<!-- TTS -->
<div hidden$='[[computeHideTTS(ttsLoaded, supportsPlayMedia)]]' class='layout horizontal end'>
<paper-input
Expand Down Expand Up @@ -170,6 +182,17 @@
observer: 'handleSourceChanged',
},

soundMode: {
type: String,
value: '',
},

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

volumeSliderValue: {
type: Number,
value: 0,
Expand Down Expand Up @@ -230,6 +253,11 @@
value: false,
},

supportsSelectSoundMode: {
type: Boolean,
value: false,
},

supportsPlay: {
type: Boolean,
value: false,
Expand All @@ -251,6 +279,7 @@
this.volumeSliderValue = newVal.attributes.volume_level * 100;
this.isMuted = newVal.attributes.is_volume_muted;
this.source = newVal.attributes.source;
this.soundMode = newVal.attributes.sound_mode;
this.supportsPause = (newVal.attributes.supported_features & 1) !== 0;
this.supportsVolumeSet = (newVal.attributes.supported_features & 4) !== 0;
this.supportsVolumeMute = (newVal.attributes.supported_features & 8) !== 0;
Expand All @@ -262,10 +291,15 @@
this.supportsVolumeButtons = (newVal.attributes.supported_features & 1024) !== 0;
this.supportsSelectSource = (newVal.attributes.supported_features & 2048) !== 0;
this.supportsPlay = (newVal.attributes.supported_features & 16384) !== 0;
this.supportsSelectSoundMode = (newVal.attributes.supported_features & 65536) !== 0;

if (newVal.attributes.source_list !== undefined) {
this.sourceIndex = newVal.attributes.source_list.indexOf(this.source);
}

if (newVal.attributes.sound_mode_list !== undefined) {
this.soundModeIndex = newVal.attributes.sound_mode_list.indexOf(this.soundMode);
}
}

if (oldVal) {
Expand Down Expand Up @@ -314,6 +348,10 @@
return stateObj.attributes.source_list.indexOf(stateObj.attributes.source);
}

computeHideSelectSoundMode(isOff, supportsSelectSoundMode) {
return isOff || !supportsSelectSoundMode;
}

computeHideTTS(ttsLoaded, supportsPlayMedia) {
return !ttsLoaded || !supportsPlayMedia;
}
Expand Down Expand Up @@ -359,6 +397,27 @@
this.callService('select_source', { source: sourceInput });
}

handleSoundModeChanged(soundModeIndex, soundModeIndexOld) {
var soundModeInput;

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.

No need to predeclare variables.

Just use const when you assign it.

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.

All handle's are done with var instead of const throught this file.
honestly I don't know the exact diffrence but I think it might be better to keep the file uniform and do the same thing as done in the rest of the file.

Basically I made a copy of the Source input, so everything is done in a similar way as the already implemented Source input.

// Selected Option will transition to '' before transitioning to new value
if (!this.stateObj
|| this.stateObj.attributes.sound_mode_list === undefined
|| soundModeIndex < 0
|| soundModeIndex >= this.stateObj.attributes.sound_mode_list.length
|| soundModeIndexOld === undefined
) {
return;
}

soundModeInput = this.stateObj.attributes.sound_mode_list[soundModeIndex];

if (soundModeInput === this.stateObj.attributes.sound_mode) {
return;
}

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

handleVolumeTap() {
if (!this.supportsVolumeMute) {
return;
Expand Down