Skip to content

Commit

Permalink
Merge pull request #3 from balloob/media-player-muting
Browse files Browse the repository at this point in the history
Volume muting fixes
  • Loading branch information
hansmbakker committed Jun 1, 2015
2 parents 21cf7ce + a3f2f7c commit e9c0cb7
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 73 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/frontend/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "775f3ebcfb3fa43833494f0b9676ac88"
VERSION = "2d15135e9bfd0ee5b023d9abb79be62d"
104 changes: 53 additions & 51 deletions homeassistant/components/frontend/www_static/frontend.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -89,7 +89,7 @@
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;
}

this.debounce('more-info-volume-animation-finish', function() {
Expand All @@ -113,8 +113,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) {
Expand Down
18 changes: 13 additions & 5 deletions homeassistant/components/media_player/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
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'
Expand Down Expand Up @@ -97,7 +97,7 @@ def volume_mute(hass, entity_id=None):


def volume_set(hass, entity_id=None, volume=None):
""" Send the media player the command to set the volume at a given level. """
""" Set volume on media player. """
data = {
key: value for key, value in [
(ATTR_ENTITY_ID, entity_id),
Expand Down Expand Up @@ -183,9 +183,11 @@ def volume_set_service(service, volume):
""" 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:
Expand All @@ -199,6 +201,9 @@ def volume_mute_service(service, mute):
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(
Expand All @@ -212,6 +217,9 @@ def play_youtube_video_service(service, media_id):
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"))
Expand Down
10 changes: 4 additions & 6 deletions homeassistant/components/media_player/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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)

Expand Down Expand Up @@ -118,9 +118,7 @@ def state_attributes(self):

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
Expand Down Expand Up @@ -161,11 +159,11 @@ def volume_down(self):
self.cast.volume_down()

def volume_mute(self, mute):
""" Service to send the chromecast the command to mute (true) or unmute (false). """
""" Set media player to mute volume. """
self.cast.set_volume_muted(mute)

def volume_set(self, volume):
""" Service to send the chromecast the command to set the volume level. """
""" Set media player volume, range of volume 0..1 """
self.cast.set_volume(volume)

def media_play_pause(self):
Expand Down
22 changes: 21 additions & 1 deletion homeassistant/components/media_player/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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


Expand All @@ -33,6 +33,7 @@ def __init__(self, name, youtube_id=None, media_title=None):
self.youtube_id = youtube_id
self.media_title = media_title
self.volume = 1.0
self.is_volume_muted = False

@property
def should_poll(self):
Expand Down Expand Up @@ -60,6 +61,7 @@ def state_attributes(self):
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)
}
Expand All @@ -71,35 +73,53 @@ def state_attributes(self):

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()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e9c0cb7

Please sign in to comment.