Volume muting fixes

This commit is contained in:
Paulus Schoutsen 2015-05-31 21:07:58 -07:00
parent 21cf7ceb07
commit 15c3e2f516
7 changed files with 99 additions and 70 deletions

View file

@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "775f3ebcfb3fa43833494f0b9676ac88"
VERSION = "2d15135e9bfd0ee5b023d9abb79be62d"

File diff suppressed because one or more lines are too long

View file

@ -9,7 +9,7 @@
}
/* Accent the power button because the user should use that first */
paper-icon-button[icon="power-settings-new"] {
paper-icon-button[focus] {
color: var(--accent-color);
}
@ -29,14 +29,14 @@
<div class$='[[computeClassNames(stateObj)]]'>
<div class='layout horizontal'>
<div class='flex'>
<paper-icon-button icon='power-settings-new'
<paper-icon-button icon='power-settings-new' focus$='[[isIdle]]'
on-tap='handleTogglePower'></paper-icon-button>
</div>
<div>
<template is='dom-if' if='[[!isIdle]]'>
<paper-icon-button icon='av:skip-previous'
on-tap='handlePrevious'></paper-icon-button>
<paper-icon-button icon='[[computePlayPauseIcon(stateObj)]]'
<paper-icon-button icon='[[computePlayPauseIcon(stateObj)]]' focus$
on-tap='handlePlayPause'></paper-icon-button>
<paper-icon-button icon='av:skip-next'
on-tap='handleNext'></paper-icon-button>
@ -45,8 +45,8 @@
</div>
<div class='volume center horizontal layout'>
<paper-icon-button on-tap="handleVolumeTap"
icon="[[computeMuteVolumeIcon(stateObj)]]"></paper-icon-button>
<paper-slider
icon="[[computeMuteVolumeIcon(isMuted)]]"></paper-icon-button>
<paper-slider hidden='[[isMuted]]'
min='0' max='100' value='{{volumeSliderValue}}'
on-change='volumeSliderChanged' class='flex'>
</paper-slider>
@ -89,7 +89,8 @@
stateObjChanged: function(newVal, oldVal) {
if (newVal) {
this.volumeSliderValue = newVal.attributes.media_volume * 100;
this.isMuted = newVal.attributes.media_is_muted;
this.isMuted = newVal.attributes.media_is_volume_muted;
console.log(this.isMuted);
}
this.debounce('more-info-volume-animation-finish', function() {
@ -113,8 +114,8 @@
return isIdle ? 'Turn on' : 'Turn off';
},
computeMuteVolumeIcon: function(stateObj) {
return this.isMuted ? 'av:volume-up' : 'av:volume-off';
computeMuteVolumeIcon: function(isMuted) {
return isMuted ? 'av:volume-off' : 'av:volume-up';
},
computePlayPauseIcon: function(stateObj) {

View file

@ -39,7 +39,7 @@ ATTR_MEDIA_ARTIST = 'media_artist'
ATTR_MEDIA_ALBUM = 'media_album'
ATTR_MEDIA_IMAGE_URL = 'media_image_url'
ATTR_MEDIA_VOLUME = 'media_volume'
ATTR_MEDIA_IS_MUTED = 'media_is_muted'
ATTR_MEDIA_IS_VOLUME_MUTED = 'media_is_volume_muted'
ATTR_MEDIA_DURATION = 'media_duration'
MEDIA_STATE_UNKNOWN = 'unknown'
@ -183,9 +183,11 @@ def setup(hass, config):
""" Set specified volume on the media player. """
target_players = component.extract_from_service(service)
if volume:
for player in target_players:
player.volume_set(volume)
for player in target_players:
player.volume_set(volume)
if player.should_poll:
player.update_ha_state(True)
hass.services.register(DOMAIN, SERVICE_VOLUME_SET,
lambda service:
@ -199,6 +201,9 @@ def setup(hass, config):
for player in target_players:
player.volume_mute(mute)
if player.should_poll:
player.update_ha_state(True)
hass.services.register(DOMAIN, SERVICE_VOLUME_MUTE,
lambda service:
volume_mute_service(
@ -212,6 +217,9 @@ def setup(hass, config):
for player in target_players:
player.play_youtube(media_id)
if player.should_poll:
player.update_ha_state(True)
hass.services.register(DOMAIN, "start_fireplace",
lambda service:
play_youtube_video_service(service, "eyU3bRy2x44"))

View file

@ -21,7 +21,7 @@ from homeassistant.const import ATTR_ENTITY_PICTURE
from homeassistant.components.media_player import (
MediaPlayerDevice, STATE_NO_APP, ATTR_MEDIA_STATE, ATTR_MEDIA_TITLE,
ATTR_MEDIA_CONTENT_ID, ATTR_MEDIA_DURATION,
ATTR_MEDIA_VOLUME, ATTR_MEDIA_IS_MUTED,
ATTR_MEDIA_VOLUME, ATTR_MEDIA_IS_VOLUME_MUTED,
MEDIA_STATE_PLAYING, MEDIA_STATE_PAUSED, MEDIA_STATE_STOPPED,
MEDIA_STATE_UNKNOWN)
@ -118,9 +118,7 @@ class CastDevice(MediaPlayerDevice):
if cast_status:
state_attr[ATTR_MEDIA_VOLUME] = cast_status.volume_level
if cast_status:
state_attr[ATTR_MEDIA_IS_MUTED] = cast_status.volume_muted
state_attr[ATTR_MEDIA_IS_VOLUME_MUTED] = cast_status.volume_muted
if media_status.content_id:
state_attr[ATTR_MEDIA_CONTENT_ID] = media_status.content_id

View file

@ -9,7 +9,7 @@ from homeassistant.components.media_player import (
MediaPlayerDevice, STATE_NO_APP, ATTR_MEDIA_STATE,
ATTR_MEDIA_CONTENT_ID, ATTR_MEDIA_TITLE, ATTR_MEDIA_DURATION,
ATTR_MEDIA_VOLUME, MEDIA_STATE_PLAYING, MEDIA_STATE_STOPPED,
YOUTUBE_COVER_URL_FORMAT)
YOUTUBE_COVER_URL_FORMAT, ATTR_MEDIA_IS_VOLUME_MUTED)
from homeassistant.const import ATTR_ENTITY_PICTURE
@ -33,6 +33,7 @@ class DemoMediaPlayer(MediaPlayerDevice):
self.youtube_id = youtube_id
self.media_title = media_title
self.volume = 1.0
self.is_volume_muted = False
@property
def should_poll(self):
@ -60,6 +61,7 @@ class DemoMediaPlayer(MediaPlayerDevice):
ATTR_MEDIA_TITLE: self.media_title,
ATTR_MEDIA_DURATION: 100,
ATTR_MEDIA_VOLUME: self.volume,
ATTR_MEDIA_IS_VOLUME_MUTED: self.is_volume_muted,
ATTR_ENTITY_PICTURE:
YOUTUBE_COVER_URL_FORMAT.format(self.youtube_id)
}
@ -71,35 +73,53 @@ class DemoMediaPlayer(MediaPlayerDevice):
return state_attr
def turn_on(self):
""" turn_off media player. """
self.youtube_id = "eyU3bRy2x44"
self.is_playing = False
self.update_ha_state()
def turn_off(self):
""" turn_off media player. """
self.youtube_id = None
self.is_playing = False
self.update_ha_state()
def volume_up(self):
""" volume_up media player. """
if self.volume < 1:
self.volume += 0.1
self.update_ha_state()
def volume_down(self):
""" volume_down media player. """
if self.volume > 0:
self.volume -= 0.1
self.update_ha_state()
def volume_mute(self, mute):
""" mute (true) or unmute (false) media player. """
self.is_volume_muted = mute
self.update_ha_state()
def media_play_pause(self):
""" media_play_pause media player. """
self.is_playing = not self.is_playing
self.update_ha_state()
def media_play(self):
""" media_play media player. """
self.is_playing = True
self.update_ha_state()
def media_pause(self):
""" media_pause media player. """
self.is_playing = False
self.update_ha_state()
def play_youtube(self, media_id):
""" Plays a YouTube media. """
self.youtube_id = media_id
self.media_title = 'Demo media title'
self.is_playing = True
self.update_ha_state()

View file

@ -18,7 +18,7 @@ phue>=0.8
ledcontroller>=1.0.7
# media_player.cast
pychromecast>=0.6.3
pychromecast>=0.6.4
# keyboard
pyuserinput>=0.1.9