mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add volume/mute button instead of text label, depends on new pychromecast method. Also I made the power button the only accented button.
This commit is contained in:
parent
5c48c87af0
commit
81245495ae
@ -1,2 +1,2 @@
|
|||||||
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
||||||
VERSION = "3c6a5149feced6c49cb97b76fdf14fee"
|
VERSION = "31e33f5ec4ad4c9355af6f40213f3168"
|
||||||
|
File diff suppressed because one or more lines are too long
@ -8,7 +8,8 @@
|
|||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
paper-icon-button {
|
/* Accent the power button because the user should use that first */
|
||||||
|
paper-icon-button[icon="power-settings-new"] {
|
||||||
color: var(--accent-color);
|
color: var(--accent-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +44,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class='volume center horizontal layout'>
|
<div class='volume center horizontal layout'>
|
||||||
<div>Volume</div>
|
<paper-icon-button on-tap="handleVolumeTap"
|
||||||
|
icon="[[computeMuteVolumeIcon(stateObj)]]"></paper-icon-button>
|
||||||
<paper-slider
|
<paper-slider
|
||||||
min='0' max='100' value='{{volumeSliderValue}}'
|
min='0' max='100' value='{{volumeSliderValue}}'
|
||||||
on-change='volumeSliderChanged' class='flex'>
|
on-change='volumeSliderChanged' class='flex'>
|
||||||
@ -73,6 +75,11 @@
|
|||||||
computed: 'computeIsIdle(stateObj)',
|
computed: 'computeIsIdle(stateObj)',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isMuted: {
|
||||||
|
type: Boolean,
|
||||||
|
value: false
|
||||||
|
},
|
||||||
|
|
||||||
volumeSliderValue: {
|
volumeSliderValue: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 0,
|
value: 0,
|
||||||
@ -82,6 +89,7 @@
|
|||||||
stateObjChanged: function(newVal, oldVal) {
|
stateObjChanged: function(newVal, oldVal) {
|
||||||
if (newVal) {
|
if (newVal) {
|
||||||
this.volumeSliderValue = newVal.attributes.media_volume * 100;
|
this.volumeSliderValue = newVal.attributes.media_volume * 100;
|
||||||
|
this.isMuted = newVal.attributes.media_is_muted;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.debounce('more-info-volume-animation-finish', function() {
|
this.debounce('more-info-volume-animation-finish', function() {
|
||||||
@ -105,6 +113,10 @@
|
|||||||
return isIdle ? 'Turn on' : 'Turn off';
|
return isIdle ? 'Turn on' : 'Turn off';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
computeMuteVolumeIcon: function(stateObj) {
|
||||||
|
return this.isMuted ? 'av:volume-up' : 'av:av:volume-off';
|
||||||
|
},
|
||||||
|
|
||||||
computePlayPauseIcon: function(stateObj) {
|
computePlayPauseIcon: function(stateObj) {
|
||||||
return stateObj.attributes.media_state == 'playing' ? 'av:pause' : 'av:play-arrow';
|
return stateObj.attributes.media_state == 'playing' ? 'av:pause' : 'av:play-arrow';
|
||||||
},
|
},
|
||||||
@ -125,11 +137,15 @@
|
|||||||
this.callService('media_next_track');
|
this.callService('media_next_track');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleVolumeTap: function() {
|
||||||
|
this.callService('volume_mute', { mute: !this.isMuted });
|
||||||
|
},
|
||||||
|
|
||||||
volumeSliderChanged: function(ev) {
|
volumeSliderChanged: function(ev) {
|
||||||
var volPercentage = parseFloat(ev.target.value);
|
var volPercentage = parseFloat(ev.target.value);
|
||||||
var vol = volPercentage > 0 ? volPercentage / 100 : 0;
|
var vol = volPercentage > 0 ? volPercentage / 100 : 0;
|
||||||
|
|
||||||
this.callService('volume_set', {volume: vol});
|
this.callService('volume_set', { volume: vol });
|
||||||
},
|
},
|
||||||
|
|
||||||
callService: function(service, data) {
|
callService: function(service, data) {
|
||||||
|
@ -39,6 +39,7 @@ ATTR_MEDIA_ARTIST = 'media_artist'
|
|||||||
ATTR_MEDIA_ALBUM = 'media_album'
|
ATTR_MEDIA_ALBUM = 'media_album'
|
||||||
ATTR_MEDIA_IMAGE_URL = 'media_image_url'
|
ATTR_MEDIA_IMAGE_URL = 'media_image_url'
|
||||||
ATTR_MEDIA_VOLUME = 'media_volume'
|
ATTR_MEDIA_VOLUME = 'media_volume'
|
||||||
|
ATTR_MEDIA_IS_MUTED = 'media_is_muted'
|
||||||
ATTR_MEDIA_DURATION = 'media_duration'
|
ATTR_MEDIA_DURATION = 'media_duration'
|
||||||
|
|
||||||
MEDIA_STATE_UNKNOWN = 'unknown'
|
MEDIA_STATE_UNKNOWN = 'unknown'
|
||||||
@ -89,14 +90,14 @@ def volume_down(hass, entity_id=None):
|
|||||||
|
|
||||||
|
|
||||||
def volume_mute(hass, entity_id=None):
|
def volume_mute(hass, entity_id=None):
|
||||||
""" Send the media player the command for volume down. """
|
""" Send the media player the command to toggle its mute state. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_VOLUME_MUTE, data)
|
hass.services.call(DOMAIN, SERVICE_VOLUME_MUTE, data)
|
||||||
|
|
||||||
|
|
||||||
def volume_set(hass, entity_id=None, volume=None):
|
def volume_set(hass, entity_id=None, volume=None):
|
||||||
""" Send the media player the command for volume down. """
|
""" Send the media player the command to set the volume at a given level. """
|
||||||
data = {
|
data = {
|
||||||
key: value for key, value in [
|
key: value for key, value in [
|
||||||
(ATTR_ENTITY_ID, entity_id),
|
(ATTR_ENTITY_ID, entity_id),
|
||||||
@ -147,7 +148,6 @@ SERVICE_TO_METHOD = {
|
|||||||
SERVICE_TURN_OFF: 'turn_off',
|
SERVICE_TURN_OFF: 'turn_off',
|
||||||
SERVICE_VOLUME_UP: 'volume_up',
|
SERVICE_VOLUME_UP: 'volume_up',
|
||||||
SERVICE_VOLUME_DOWN: 'volume_down',
|
SERVICE_VOLUME_DOWN: 'volume_down',
|
||||||
SERVICE_VOLUME_MUTE: 'volume_mute',
|
|
||||||
SERVICE_MEDIA_PLAY_PAUSE: 'media_play_pause',
|
SERVICE_MEDIA_PLAY_PAUSE: 'media_play_pause',
|
||||||
SERVICE_MEDIA_PLAY: 'media_play',
|
SERVICE_MEDIA_PLAY: 'media_play',
|
||||||
SERVICE_MEDIA_PAUSE: 'media_pause',
|
SERVICE_MEDIA_PAUSE: 'media_pause',
|
||||||
@ -192,6 +192,18 @@ def setup(hass, config):
|
|||||||
volume_set_service(
|
volume_set_service(
|
||||||
service, service.data.get('volume')))
|
service, service.data.get('volume')))
|
||||||
|
|
||||||
|
def volume_mute_service(service, mute):
|
||||||
|
""" Mute (true) or unmute (false) the media player. """
|
||||||
|
target_players = component.extract_from_service(service)
|
||||||
|
|
||||||
|
for player in target_players:
|
||||||
|
player.volume_mute(mute)
|
||||||
|
|
||||||
|
hass.services.register(DOMAIN, SERVICE_VOLUME_MUTE,
|
||||||
|
lambda service:
|
||||||
|
volume_mute_service(
|
||||||
|
service, service.data.get('mute')))
|
||||||
|
|
||||||
def play_youtube_video_service(service, media_id):
|
def play_youtube_video_service(service, media_id):
|
||||||
""" Plays specified media_id on the media player. """
|
""" Plays specified media_id on the media player. """
|
||||||
target_players = component.extract_from_service(service)
|
target_players = component.extract_from_service(service)
|
||||||
@ -235,8 +247,8 @@ class MediaPlayerDevice(Entity):
|
|||||||
""" volume_down media player. """
|
""" volume_down media player. """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def volume_mute(self):
|
def volume_mute(self, mute):
|
||||||
""" mute media player. """
|
""" mute (true) or unmute (false) media player. """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def volume_set(self, volume):
|
def volume_set(self, volume):
|
||||||
|
@ -20,7 +20,8 @@ from homeassistant.const import ATTR_ENTITY_PICTURE
|
|||||||
# ATTR_MEDIA_ARTIST,
|
# ATTR_MEDIA_ARTIST,
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
MediaPlayerDevice, STATE_NO_APP, ATTR_MEDIA_STATE, ATTR_MEDIA_TITLE,
|
MediaPlayerDevice, STATE_NO_APP, ATTR_MEDIA_STATE, ATTR_MEDIA_TITLE,
|
||||||
ATTR_MEDIA_CONTENT_ID, ATTR_MEDIA_DURATION, ATTR_MEDIA_VOLUME,
|
ATTR_MEDIA_CONTENT_ID, ATTR_MEDIA_DURATION,
|
||||||
|
ATTR_MEDIA_VOLUME, ATTR_MEDIA_IS_MUTED,
|
||||||
MEDIA_STATE_PLAYING, MEDIA_STATE_PAUSED, MEDIA_STATE_STOPPED,
|
MEDIA_STATE_PLAYING, MEDIA_STATE_PAUSED, MEDIA_STATE_STOPPED,
|
||||||
MEDIA_STATE_UNKNOWN)
|
MEDIA_STATE_UNKNOWN)
|
||||||
|
|
||||||
@ -118,6 +119,9 @@ class CastDevice(MediaPlayerDevice):
|
|||||||
if cast_status:
|
if cast_status:
|
||||||
state_attr[ATTR_MEDIA_VOLUME] = cast_status.volume_level
|
state_attr[ATTR_MEDIA_VOLUME] = cast_status.volume_level
|
||||||
|
|
||||||
|
if cast_status:
|
||||||
|
state_attr[ATTR_MEDIA_IS_MUTED] = cast_status.volume_muted
|
||||||
|
|
||||||
if media_status.content_id:
|
if media_status.content_id:
|
||||||
state_attr[ATTR_MEDIA_CONTENT_ID] = media_status.content_id
|
state_attr[ATTR_MEDIA_CONTENT_ID] = media_status.content_id
|
||||||
|
|
||||||
@ -156,12 +160,12 @@ class CastDevice(MediaPlayerDevice):
|
|||||||
""" Service to send the chromecast the command for volume down. """
|
""" Service to send the chromecast the command for volume down. """
|
||||||
self.cast.volume_down()
|
self.cast.volume_down()
|
||||||
|
|
||||||
def volume_mute(self):
|
def volume_mute(self, mute):
|
||||||
""" Service to send the chromecast the command for volume up. """
|
""" Service to send the chromecast the command to mute (true) or unmute (false). """
|
||||||
self.cast.set_volume(0)
|
self.cast.set_volume_muted(mute)
|
||||||
|
|
||||||
def volume_set(self, volume):
|
def volume_set(self, volume):
|
||||||
""" Service to send the chromecast the command for volume down. """
|
""" Service to send the chromecast the command to set the volume level. """
|
||||||
self.cast.set_volume(volume)
|
self.cast.set_volume(volume)
|
||||||
|
|
||||||
def media_play_pause(self):
|
def media_play_pause(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user