Media Player and cast improvements

This commit is contained in:
Paulus Schoutsen 2015-05-31 00:38:14 -07:00
parent 678be46bb9
commit afd99a0c6c
7 changed files with 49 additions and 22 deletions

View File

@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """ """ DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "d9e860658bd8d9767b748b1b193776e6" VERSION = "6fb0e76d325bb7472fa25355e60539cd"

View File

@ -22208,13 +22208,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<div class="horizontal justified layout"> <div class="horizontal justified layout">
<state-info state-obj="[[stateObj]]"></state-info> <state-info state-obj="[[stateObj]]"></state-info>
<div class="state"> <div class="state">
<template is="dom-if" if="[[stateObj.attributes.media_title]]"> <div class="main-text">[[computePrimaryText(stateObj)]]</div>
<div class="main-text">[[stateObj.attributes.media_title]]</div> <div class="secondary-text">[[computeSecondaryText(stateObj)]]</div>
<div class="secondary-text">[[stateObj.stateDisplay]]</div>
</template>
<template is="dom-if" if="[[!stateObj.attributes.media_title]]">
<div class="main-text">[[stateObj.stateDisplay]]</div>
</template>
</div> </div>
</div> </div>
</template> </template>
@ -22230,6 +22225,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
type: Object, type: Object,
}, },
}, },
computePrimaryText: function(stateObj) {
return stateObj.attributes.media_title || stateObj.stateDisplay;
},
computeSecondaryText: function(stateObj) {
return stateObj.attributes.media_title ? stateObj.stateDisplay : '';
},
}); });
})(); })();
</script> </script>
@ -25726,9 +25729,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<template> <template>
<div class="layout horizontal"> <div class="layout horizontal">
<div class="flex"> <div class="flex">
<paper-button on-tap="handleTogglePower">[[computePowerButtonCaption(isIdle)]]</paper-button> <paper-icon-button icon="power-settings-new" on-tap="handleTogglePower"></paper-icon-button>
</div> </div>
<div class=""> <div>
<template is="dom-if" if="[[!isIdle]]"> <template is="dom-if" if="[[!isIdle]]">
<paper-icon-button icon="av:skip-previous" on-tap="handlePrevious"></paper-icon-button> <paper-icon-button icon="av:skip-previous" on-tap="handlePrevious"></paper-icon-button>
<paper-icon-button icon="[[computePlayPauseIcon(stateObj)]]" on-tap="handlePlayPause"></paper-icon-button> <paper-icon-button icon="[[computePlayPauseIcon(stateObj)]]" on-tap="handlePlayPause"></paper-icon-button>

View File

@ -32,13 +32,8 @@
<div class='horizontal justified layout'> <div class='horizontal justified layout'>
<state-info state-obj="[[stateObj]]"></state-info> <state-info state-obj="[[stateObj]]"></state-info>
<div class='state'> <div class='state'>
<template is='dom-if' if='[[stateObj.attributes.media_title]]'> <div class='main-text'>[[computePrimaryText(stateObj)]]</div>
<div class='main-text'>[[stateObj.attributes.media_title]]</div> <div class='secondary-text'>[[computeSecondaryText(stateObj)]]</div>
<div class='secondary-text'>[[stateObj.stateDisplay]]</div>
</template>
<template is='dom-if' if='[[!stateObj.attributes.media_title]]'>
<div class='main-text'>[[stateObj.stateDisplay]]</div>
</template>
</div> </div>
</div> </div>
</template> </template>
@ -54,6 +49,14 @@
type: Object, type: Object,
}, },
}, },
computePrimaryText: function(stateObj) {
return stateObj.attributes.media_title || stateObj.stateDisplay;
},
computeSecondaryText: function(stateObj) {
return stateObj.attributes.media_title ? stateObj.stateDisplay : '';
},
}); });
})(); })();
</script> </script>

View File

@ -1,6 +1,5 @@
<link rel='import' href='../bower_components/polymer/polymer.html'> <link rel='import' href='../bower_components/polymer/polymer.html'>
<link rel='import' href='../bower_components/paper-button/paper-button.html'>
<link rel='import' href='../bower_components/paper-icon-button/paper-icon-button.html'> <link rel='import' href='../bower_components/paper-icon-button/paper-icon-button.html'>
<dom-module id='more-info-media_player'> <dom-module id='more-info-media_player'>
@ -16,9 +15,10 @@
<template> <template>
<div class='layout horizontal'> <div class='layout horizontal'>
<div class='flex'> <div class='flex'>
<paper-button on-tap='handleTogglePower'>[[computePowerButtonCaption(isIdle)]]</paper-button> <paper-icon-button icon='power-settings-new'
on-tap='handleTogglePower'></paper-icon-button>
</div> </div>
<div class=''> <div>
<template is='dom-if' if='[[!isIdle]]'> <template is='dom-if' if='[[!isIdle]]'>
<paper-icon-button icon='av:skip-previous' <paper-icon-button icon='av:skip-previous'
on-tap='handlePrevious'></paper-icon-button> on-tap='handlePrevious'></paper-icon-button>

View File

@ -130,6 +130,7 @@ SERVICE_TO_METHOD = {
SERVICE_MEDIA_PLAY: 'media_play', SERVICE_MEDIA_PLAY: 'media_play',
SERVICE_MEDIA_PAUSE: 'media_pause', SERVICE_MEDIA_PAUSE: 'media_pause',
SERVICE_MEDIA_NEXT_TRACK: 'media_next_track', SERVICE_MEDIA_NEXT_TRACK: 'media_next_track',
SERVICE_MEDIA_PREV_TRACK: 'media_prev_track',
} }
@ -211,6 +212,10 @@ class MediaPlayerDevice(Entity):
""" media_pause media player. """ """ media_pause media player. """
pass pass
def media_prev_track(self):
""" media_prev_track media player. """
pass
def media_next_track(self): def media_next_track(self):
""" media_next_track media player. """ """ media_next_track media player. """
pass pass

View File

@ -24,6 +24,8 @@ from homeassistant.components.media_player import (
MEDIA_STATE_PLAYING, MEDIA_STATE_PAUSED, MEDIA_STATE_STOPPED, MEDIA_STATE_PLAYING, MEDIA_STATE_PAUSED, MEDIA_STATE_STOPPED,
MEDIA_STATE_UNKNOWN) MEDIA_STATE_UNKNOWN)
CAST_SPLASH = 'https://home-assistant.io/images/cast/splash.png'
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
@ -130,6 +132,13 @@ class CastDevice(MediaPlayerDevice):
return state_attr return state_attr
def turn_on(self):
""" Turns on the ChromeCast. """
# The only way we can turn the Chromecast is on is by launching an app
if not self.cast.status.is_active_input:
self.cast.play_media(
CAST_SPLASH, pychromecast.STREAM_TYPE_BUFFERED)
def turn_off(self): def turn_off(self):
""" Service to exit any running app on the specimedia player ChromeCast and """ Service to exit any running app on the specimedia player ChromeCast and
shows idle screen. Will quit all ChromeCasts if nothing specified. shows idle screen. Will quit all ChromeCasts if nothing specified.
@ -163,6 +172,14 @@ class CastDevice(MediaPlayerDevice):
if self.media_state == MEDIA_STATE_PLAYING: if self.media_state == MEDIA_STATE_PLAYING:
self.cast.media_controller.pause() self.cast.media_controller.pause()
def media_prev_track(self):
""" media_prev_track media player. """
self.cast.media_controller.rewind()
def media_next_track(self):
""" media_next_track media player. """
self.cast.media_controller.skip()
def play_youtube_video(self, video_id): def play_youtube_video(self, video_id):
""" Plays specified video_id on the Chromecast's YouTube channel. """ """ Plays specified video_id on the Chromecast's YouTube channel. """
self.youtube.play_video(video_id) self.youtube.play_video(video_id)
@ -170,7 +187,6 @@ class CastDevice(MediaPlayerDevice):
def new_cast_status(self, status): def new_cast_status(self, status):
""" Called when a new cast status is received. """ """ Called when a new cast status is received. """
self.cast_status = status self.cast_status = status
self.media_status = None
self.update_ha_state() self.update_ha_state()
def new_media_status(self, status): def new_media_status(self, status):

View File

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