mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use voluptuous for Yamaha receiver (#3210)
* Migrate to voluptuous * Add missing configuration variables
This commit is contained in:
parent
7528da455c
commit
68def21615
@ -6,10 +6,13 @@ https://home-assistant.io/components/media_player.yamaha/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
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, MediaPlayerDevice)
|
SUPPORT_SELECT_SOURCE, MediaPlayerDevice, PLATFORM_SCHEMA)
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON
|
from homeassistant.const import (CONF_NAME, STATE_OFF, STATE_ON)
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['rxv==0.1.11']
|
REQUIREMENTS = ['rxv==0.1.11']
|
||||||
|
|
||||||
@ -21,16 +24,26 @@ SUPPORT_YAMAHA = SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
|||||||
CONF_SOURCE_NAMES = 'source_names'
|
CONF_SOURCE_NAMES = 'source_names'
|
||||||
CONF_SOURCE_IGNORE = 'source_ignore'
|
CONF_SOURCE_IGNORE = 'source_ignore'
|
||||||
|
|
||||||
|
DEFAULT_NAME = 'Yamaha Receiver'
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
vol.Optional(CONF_SOURCE_IGNORE, default=[]):
|
||||||
|
vol.All(cv.ensure_list, [cv.string]),
|
||||||
|
vol.Optional(CONF_SOURCE_NAMES, default={}): {cv.string: cv.string},
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Yamaha platform."""
|
"""Setup the Yamaha platform."""
|
||||||
import rxv
|
import rxv
|
||||||
|
|
||||||
source_ignore = config.get(CONF_SOURCE_IGNORE, [])
|
name = config.get(CONF_NAME)
|
||||||
source_names = config.get(CONF_SOURCE_NAMES, {})
|
source_ignore = config.get(CONF_SOURCE_IGNORE)
|
||||||
|
source_names = config.get(CONF_SOURCE_NAMES)
|
||||||
|
|
||||||
add_devices(
|
add_devices(
|
||||||
YamahaDevice(config.get("name"), receiver, source_ignore, source_names)
|
YamahaDevice(name, receiver, source_ignore, source_names)
|
||||||
for receiver in rxv.find())
|
for receiver in rxv.find())
|
||||||
|
|
||||||
|
|
||||||
@ -66,8 +79,8 @@ class YamahaDevice(MediaPlayerDevice):
|
|||||||
self.build_source_list()
|
self.build_source_list()
|
||||||
|
|
||||||
current_source = self._receiver.input
|
current_source = self._receiver.input
|
||||||
self._current_source = self._source_names.get(current_source,
|
self._current_source = self._source_names.get(
|
||||||
current_source)
|
current_source, current_source)
|
||||||
|
|
||||||
def build_source_list(self):
|
def build_source_list(self):
|
||||||
"""Build the source list."""
|
"""Build the source list."""
|
||||||
@ -135,5 +148,4 @@ class YamahaDevice(MediaPlayerDevice):
|
|||||||
|
|
||||||
def select_source(self, source):
|
def select_source(self, source):
|
||||||
"""Select input source."""
|
"""Select input source."""
|
||||||
self._receiver.input = self._reverse_mapping.get(source,
|
self._receiver.input = self._reverse_mapping.get(source, source)
|
||||||
source)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user