mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Yamaha zones (#3920)
* Enhance yamaha component This enhances the yamaha component to create 1 player per zone, instead of only one play, which provides direct control of the various zones for the player. It also exposes play_media for NET_RADIO sources, which allows direct setting of that. This requires code changes in rxv 0.2.0, so the requirement dependency is raised. * Support current playback metadata for NET_RADIO When on NET RADIO, support the currently playing information.
This commit is contained in:
parent
f1b658ea5d
commit
7da47852d4
@ -10,16 +10,19 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
|
||||
SUPPORT_SELECT_SOURCE, MediaPlayerDevice, PLATFORM_SCHEMA)
|
||||
SUPPORT_SELECT_SOURCE, SUPPORT_PLAY_MEDIA,
|
||||
MEDIA_TYPE_MUSIC,
|
||||
MediaPlayerDevice, PLATFORM_SCHEMA)
|
||||
from homeassistant.const import (CONF_NAME, CONF_HOST, STATE_OFF, STATE_ON)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['rxv==0.1.11']
|
||||
REQUIREMENTS = ['rxv==0.2.0']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
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
|
||||
|
||||
CONF_SOURCE_NAMES = 'source_names'
|
||||
CONF_SOURCE_IGNORE = 'source_ignore'
|
||||
@ -45,11 +48,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
source_names = config.get(CONF_SOURCE_NAMES)
|
||||
|
||||
if host is None:
|
||||
receivers = rxv.find()
|
||||
receivers = []
|
||||
for recv in rxv.find():
|
||||
receivers.extend(recv.zone_controllers())
|
||||
else:
|
||||
receivers = \
|
||||
[rxv.RXV("http://{}:80/YamahaRemoteControl/ctrl".format(host),
|
||||
name)]
|
||||
ctrl_url = "http://{}:80/YamahaRemoteControl/ctrl".format(host)
|
||||
receivers = rxv.RXV(ctrl_url, name).zone_controllers()
|
||||
|
||||
add_devices(
|
||||
YamahaDevice(name, receiver, source_ignore, source_names)
|
||||
@ -74,6 +78,7 @@ class YamahaDevice(MediaPlayerDevice):
|
||||
self._reverse_mapping = None
|
||||
self.update()
|
||||
self._name = name
|
||||
self._zone = receiver.zone
|
||||
|
||||
def update(self):
|
||||
"""Get the latest details from the device."""
|
||||
@ -104,7 +109,11 @@ class YamahaDevice(MediaPlayerDevice):
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._name
|
||||
name = self._name
|
||||
if self._zone != "Main_Zone":
|
||||
# Zone will be one of Main_Zone, Zone_2, Zone_3
|
||||
name += " " + self._zone.replace('_', ' ')
|
||||
return name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
@ -158,3 +167,35 @@ class YamahaDevice(MediaPlayerDevice):
|
||||
def select_source(self, source):
|
||||
"""Select input source."""
|
||||
self._receiver.input = self._reverse_mapping.get(source, source)
|
||||
|
||||
def play_media(self, media_type, media_id, **kwargs):
|
||||
"""Play media from an ID.
|
||||
|
||||
This exposes a pass through for various input sources in the
|
||||
Yamaha to direct play certain kinds of media. media_type is
|
||||
treated as the input type that we are setting, and media id is
|
||||
specific to it.
|
||||
"""
|
||||
if media_type == "NET RADIO":
|
||||
self._receiver.net_radio(media_id)
|
||||
|
||||
@property
|
||||
def media_content_type(self):
|
||||
"""Return the media content type."""
|
||||
if self.source == "NET RADIO":
|
||||
return MEDIA_TYPE_MUSIC
|
||||
|
||||
@property
|
||||
def media_title(self):
|
||||
"""Return the media title.
|
||||
|
||||
This will vary by input source, as they provide different
|
||||
information in metadata.
|
||||
|
||||
"""
|
||||
if self.source == "NET RADIO":
|
||||
info = self._receiver.play_status()
|
||||
if info.song:
|
||||
return "%s: %s" % (info.station, info.song)
|
||||
else:
|
||||
return info.station
|
||||
|
@ -439,7 +439,7 @@ radiotherm==1.2
|
||||
# rpi-rf==0.9.5
|
||||
|
||||
# homeassistant.components.media_player.yamaha
|
||||
rxv==0.1.11
|
||||
rxv==0.2.0
|
||||
|
||||
# homeassistant.components.media_player.samsungtv
|
||||
samsungctl==0.5.1
|
||||
|
Loading…
x
Reference in New Issue
Block a user