Merge pull request #47 from TheRealLink/yamaha-input

added input select to media_player
This commit is contained in:
Paulus Schoutsen 2016-04-14 13:10:27 -07:00
commit 1ad673ff6f
2 changed files with 64 additions and 0 deletions

View File

@ -24,6 +24,15 @@
.has-volume_level .volume { .has-volume_level .volume {
max-height: 40px; max-height: 40px;
} }
iron-icon.source-input {
padding: 7px;
margin-top: 15px;
}
paper-dropdown-menu.source-input {
margin-left: 10px;
}
</style> </style>
<template> <template>
<div class$='[[computeClassNames(stateObj)]]'> <div class$='[[computeClassNames(stateObj)]]'>
@ -64,6 +73,16 @@
on-change='volumeSliderChanged' class='flex'> on-change='volumeSliderChanged' class='flex'>
</paper-slider> </paper-slider>
</div> </div>
<div class='controls layout horizontal justified' hidden$='[[!supportsSelectSource]]'>
<iron-icon class="source-input" icon="mdi:login-variant"></iron-icon>
<paper-dropdown-menu class="source-input" label-float label='Source'>
<paper-menu class="dropdown-content" selected="{{sourceIndex}}">
<template is='dom-repeat' items='[[stateObj.attributes.source_list]]'>
<paper-item>[[item]]</paper-item>
</template>
</paper-menu>
</paper-dropdown-menu>
</div>
</div> </div>
</template> </template>
</dom-module> </dom-module>

View File

@ -30,6 +30,17 @@ export default new Polymer({
value: false, value: false,
}, },
source: {
type: String,
value: '',
},
sourceIndex: {
type: Number,
value: 0,
observer: 'handleSourceChanged',
},
volumeSliderValue: { volumeSliderValue: {
type: Number, type: Number,
value: 0, value: 0,
@ -75,6 +86,11 @@ export default new Polymer({
value: false, value: false,
}, },
supportsSelectSource: {
type: Boolean,
value: false,
},
hasMediaControl: { hasMediaControl: {
type: Boolean, type: Boolean,
value: false, value: false,
@ -91,6 +107,8 @@ export default new Polymer({
this.hasMediaControl = hasMediaStates.indexOf(newVal.state) !== -1; this.hasMediaControl = hasMediaStates.indexOf(newVal.state) !== -1;
this.volumeSliderValue = newVal.attributes.volume_level * 100; this.volumeSliderValue = newVal.attributes.volume_level * 100;
this.isMuted = newVal.attributes.is_volume_muted; this.isMuted = newVal.attributes.is_volume_muted;
this.source = newVal.attributes.source;
this.sourceIndex = 0;
this.supportsPause = (newVal.attributes.supported_media_commands & 1) !== 0; this.supportsPause = (newVal.attributes.supported_media_commands & 1) !== 0;
this.supportsVolumeSet = (newVal.attributes.supported_media_commands & 4) !== 0; this.supportsVolumeSet = (newVal.attributes.supported_media_commands & 4) !== 0;
this.supportsVolumeMute = (newVal.attributes.supported_media_commands & 8) !== 0; this.supportsVolumeMute = (newVal.attributes.supported_media_commands & 8) !== 0;
@ -99,6 +117,11 @@ export default new Polymer({
this.supportsTurnOn = (newVal.attributes.supported_media_commands & 128) !== 0; this.supportsTurnOn = (newVal.attributes.supported_media_commands & 128) !== 0;
this.supportsTurnOff = (newVal.attributes.supported_media_commands & 256) !== 0; this.supportsTurnOff = (newVal.attributes.supported_media_commands & 256) !== 0;
this.supportsVolumeButtons = (newVal.attributes.supported_media_commands & 1024) !== 0; this.supportsVolumeButtons = (newVal.attributes.supported_media_commands & 1024) !== 0;
this.supportsSelectSource = (newVal.attributes.supported_media_commands & 2048) !== 0;
if (newVal.attributes.source_list !== undefined) {
this.sourceIndex = newVal.attributes.source_list.indexOf(this.source);
}
} }
this.async(() => this.fire('iron-resize'), 500); this.async(() => this.fire('iron-resize'), 500);
@ -135,6 +158,10 @@ export default new Polymer({
return isOff ? !supportsTurnOn : !supportsTurnOff; return isOff ? !supportsTurnOn : !supportsTurnOff;
}, },
computeSelectedSource(stateObj) {
return stateObj.attributes.source_list.indexOf(stateObj.attributes.source);
},
handleTogglePower() { handleTogglePower() {
this.callService(this.isOff ? 'turn_on' : 'turn_off'); this.callService(this.isOff ? 'turn_on' : 'turn_off');
}, },
@ -151,6 +178,24 @@ export default new Polymer({
this.callService('media_next_track'); this.callService('media_next_track');
}, },
handleSourceChanged(sourceIndex) {
// Selected Option will transition to '' before transitioning to new value
if (!this.stateObj
|| this.stateObj.attributes.source_list === undefined
|| sourceIndex < 0
|| sourceIndex >= this.stateObj.attributes.source_list.length
) {
return;
}
const sourceInput = this.stateObj.attributes.source_list[sourceIndex];
if (sourceInput === this.stateObj.attributes.source) {
return;
}
this.callService('select_source', { source: sourceInput });
},
handleVolumeTap() { handleVolumeTap() {
if (!this.supportsVolumeMute) { if (!this.supportsVolumeMute) {
return; return;