-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add sound mode support (media_player frontend) #815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,18 @@ | |
| </paper-listbox> | ||
| </paper-dropdown-menu> | ||
| </div> | ||
| <!-- SOUND MODE PICKER --> | ||
| <div class='controls layout horizontal justified' | ||
| hidden$='[[computeHideSelectSoundMode(isOff, supportsSelectSoundMode)]]'> | ||
| <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 | ||
|
|
@@ -170,6 +182,17 @@ | |
| observer: 'handleSourceChanged', | ||
| }, | ||
|
|
||
| soundMode: { | ||
| type: String, | ||
| value: '', | ||
| }, | ||
|
|
||
| soundModeIndex: { | ||
| type: Number, | ||
| value: 0, | ||
| observer: 'handleSoundModeChanged', | ||
| }, | ||
|
|
||
| volumeSliderValue: { | ||
| type: Number, | ||
| value: 0, | ||
|
|
@@ -230,6 +253,11 @@ | |
| value: false, | ||
| }, | ||
|
|
||
| supportsSelectSoundMode: { | ||
| type: Boolean, | ||
| value: false, | ||
| }, | ||
|
|
||
| supportsPlay: { | ||
| type: Boolean, | ||
| value: false, | ||
|
|
@@ -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; | ||
|
|
@@ -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) { | ||
|
|
@@ -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; | ||
| } | ||
|
|
@@ -359,6 +397,27 @@ | |
| this.callService('select_source', { source: sourceInput }); | ||
| } | ||
|
|
||
| handleSoundModeChanged(soundModeIndex, soundModeIndexOld) { | ||
| var soundModeInput; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to predeclare variables. Just use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dom-if it instead
There was a problem hiding this comment.
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
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).