mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Merge pull request #3985 from postlund/yamaha_additions
Improve support for Yamaha receiver
This commit is contained in:
commit
2a7b7ebd6a
@ -10,13 +10,15 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
|
SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
|
||||||
SUPPORT_SELECT_SOURCE, SUPPORT_PLAY_MEDIA,
|
SUPPORT_SELECT_SOURCE, SUPPORT_PLAY_MEDIA, SUPPORT_PAUSE, SUPPORT_STOP,
|
||||||
|
SUPPORT_NEXT_TRACK, SUPPORT_PREVIOUS_TRACK,
|
||||||
MEDIA_TYPE_MUSIC,
|
MEDIA_TYPE_MUSIC,
|
||||||
MediaPlayerDevice, PLATFORM_SCHEMA)
|
MediaPlayerDevice, PLATFORM_SCHEMA)
|
||||||
from homeassistant.const import (CONF_NAME, CONF_HOST, STATE_OFF, STATE_ON)
|
from homeassistant.const import (CONF_NAME, CONF_HOST, STATE_OFF, STATE_ON,
|
||||||
|
STATE_PLAYING, STATE_IDLE)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['rxv==0.2.0']
|
REQUIREMENTS = ['rxv==0.3.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -24,6 +26,10 @@ SUPPORT_YAMAHA = SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
|||||||
SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE | \
|
SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE | \
|
||||||
SUPPORT_PLAY_MEDIA
|
SUPPORT_PLAY_MEDIA
|
||||||
|
|
||||||
|
# Only supported by some sources
|
||||||
|
SUPPORT_PLAYBACK = SUPPORT_PLAY_MEDIA | SUPPORT_PAUSE | SUPPORT_STOP | \
|
||||||
|
SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK
|
||||||
|
|
||||||
CONF_SOURCE_NAMES = 'source_names'
|
CONF_SOURCE_NAMES = 'source_names'
|
||||||
CONF_SOURCE_IGNORE = 'source_ignore'
|
CONF_SOURCE_IGNORE = 'source_ignore'
|
||||||
CONF_ZONE_IGNORE = 'zone_ignore'
|
CONF_ZONE_IGNORE = 'zone_ignore'
|
||||||
@ -91,16 +97,25 @@ class YamahaDevice(MediaPlayerDevice):
|
|||||||
self._source_ignore = source_ignore or []
|
self._source_ignore = source_ignore or []
|
||||||
self._source_names = source_names or {}
|
self._source_names = source_names or {}
|
||||||
self._reverse_mapping = None
|
self._reverse_mapping = None
|
||||||
|
self._is_playback_supported = False
|
||||||
|
self._play_status = None
|
||||||
self.update()
|
self.update()
|
||||||
self._name = name
|
self._name = name
|
||||||
self._zone = receiver.zone
|
self._zone = receiver.zone
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest details from the device."""
|
"""Get the latest details from the device."""
|
||||||
|
self._play_status = self._receiver.play_status()
|
||||||
if self._receiver.on:
|
if self._receiver.on:
|
||||||
self._pwstate = STATE_ON
|
if self._play_status is None:
|
||||||
|
self._pwstate = STATE_ON
|
||||||
|
elif self._play_status.playing:
|
||||||
|
self._pwstate = STATE_PLAYING
|
||||||
|
else:
|
||||||
|
self._pwstate = STATE_IDLE
|
||||||
else:
|
else:
|
||||||
self._pwstate = STATE_OFF
|
self._pwstate = STATE_OFF
|
||||||
|
|
||||||
self._muted = self._receiver.mute
|
self._muted = self._receiver.mute
|
||||||
self._volume = (self._receiver.volume / 100) + 1
|
self._volume = (self._receiver.volume / 100) + 1
|
||||||
|
|
||||||
@ -110,6 +125,8 @@ class YamahaDevice(MediaPlayerDevice):
|
|||||||
current_source = self._receiver.input
|
current_source = self._receiver.input
|
||||||
self._current_source = self._source_names.get(
|
self._current_source = self._source_names.get(
|
||||||
current_source, current_source)
|
current_source, current_source)
|
||||||
|
self._is_playback_supported = self._receiver.is_playback_supported(
|
||||||
|
self._current_source)
|
||||||
|
|
||||||
def build_source_list(self):
|
def build_source_list(self):
|
||||||
"""Build the source list."""
|
"""Build the source list."""
|
||||||
@ -158,7 +175,10 @@ class YamahaDevice(MediaPlayerDevice):
|
|||||||
@property
|
@property
|
||||||
def supported_media_commands(self):
|
def supported_media_commands(self):
|
||||||
"""Flag of media commands that are supported."""
|
"""Flag of media commands that are supported."""
|
||||||
return SUPPORT_YAMAHA
|
supported_commands = SUPPORT_YAMAHA
|
||||||
|
if self._is_playback_supported:
|
||||||
|
supported_commands |= SUPPORT_PLAYBACK
|
||||||
|
return supported_commands
|
||||||
|
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
"""Turn off media player."""
|
"""Turn off media player."""
|
||||||
@ -179,6 +199,34 @@ class YamahaDevice(MediaPlayerDevice):
|
|||||||
self._receiver.on = True
|
self._receiver.on = True
|
||||||
self._volume = (self._receiver.volume / 100) + 1
|
self._volume = (self._receiver.volume / 100) + 1
|
||||||
|
|
||||||
|
def media_play(self):
|
||||||
|
"""Send play commmand."""
|
||||||
|
self._call_playback_function(self._receiver.play, "play")
|
||||||
|
|
||||||
|
def media_pause(self):
|
||||||
|
"""Send pause command."""
|
||||||
|
self._call_playback_function(self._receiver.pause, "pause")
|
||||||
|
|
||||||
|
def media_stop(self):
|
||||||
|
"""Send stop command."""
|
||||||
|
self._call_playback_function(self._receiver.stop, "stop")
|
||||||
|
|
||||||
|
def media_previous_track(self):
|
||||||
|
"""Send previous track command."""
|
||||||
|
self._call_playback_function(self._receiver.previous, "previous track")
|
||||||
|
|
||||||
|
def media_next_track(self):
|
||||||
|
"""Send next track command."""
|
||||||
|
self._call_playback_function(self._receiver.next, "next track")
|
||||||
|
|
||||||
|
def _call_playback_function(self, function, function_text):
|
||||||
|
import rxv
|
||||||
|
try:
|
||||||
|
function()
|
||||||
|
except rxv.exceptions.ResponseException:
|
||||||
|
_LOGGER.warning(
|
||||||
|
'Failed to execute %s on %s', function_text, self._name)
|
||||||
|
|
||||||
def select_source(self, source):
|
def select_source(self, source):
|
||||||
"""Select input source."""
|
"""Select input source."""
|
||||||
self._receiver.input = self._reverse_mapping.get(source, source)
|
self._receiver.input = self._reverse_mapping.get(source, source)
|
||||||
@ -194,23 +242,36 @@ class YamahaDevice(MediaPlayerDevice):
|
|||||||
if media_type == "NET RADIO":
|
if media_type == "NET RADIO":
|
||||||
self._receiver.net_radio(media_id)
|
self._receiver.net_radio(media_id)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def media_artist(self):
|
||||||
|
"""Artist of current playing media."""
|
||||||
|
if self._play_status is not None:
|
||||||
|
return self._play_status.artist
|
||||||
|
|
||||||
|
@property
|
||||||
|
def media_album_name(self):
|
||||||
|
"""Album of current playing media."""
|
||||||
|
if self._play_status is not None:
|
||||||
|
return self._play_status.album
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_content_type(self):
|
def media_content_type(self):
|
||||||
"""Return the media content type."""
|
"""Content type of current playing media."""
|
||||||
if self.source == "NET RADIO":
|
# Loose assumption that if playback is supported, we are playing music
|
||||||
|
if self._is_playback_supported:
|
||||||
return MEDIA_TYPE_MUSIC
|
return MEDIA_TYPE_MUSIC
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_title(self):
|
def media_title(self):
|
||||||
"""Return the media title.
|
"""Artist of current playing media."""
|
||||||
|
if self._play_status is not None:
|
||||||
|
song = self._play_status.song
|
||||||
|
station = self._play_status.station
|
||||||
|
|
||||||
This will vary by input source, as they provide different
|
# If both song and station is available, print both, otherwise
|
||||||
information in metadata.
|
# just the one we have.
|
||||||
|
if song and station:
|
||||||
"""
|
return '{}: {}'.format(station, song)
|
||||||
if self.source == "NET RADIO":
|
|
||||||
info = self._receiver.play_status()
|
|
||||||
if info.song:
|
|
||||||
return "%s: %s" % (info.station, info.song)
|
|
||||||
else:
|
else:
|
||||||
return info.station
|
return song or station
|
||||||
|
@ -449,7 +449,7 @@ radiotherm==1.2
|
|||||||
# rpi-rf==0.9.5
|
# rpi-rf==0.9.5
|
||||||
|
|
||||||
# homeassistant.components.media_player.yamaha
|
# homeassistant.components.media_player.yamaha
|
||||||
rxv==0.2.0
|
rxv==0.3.0
|
||||||
|
|
||||||
# homeassistant.components.media_player.samsungtv
|
# homeassistant.components.media_player.samsungtv
|
||||||
samsungctl==0.5.1
|
samsungctl==0.5.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user