Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions homeassistant/components/media_player/onkyo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
_LOGGER = logging.getLogger(__name__)

CONF_SOURCES = 'sources'
CONF_MAX_VOLUME = 'max_volume'
CONF_ZONE2 = 'zone2'

DEFAULT_NAME = 'Onkyo Receiver'
SUPPORTED_MAX_VOLUME = 80

SUPPORT_ONKYO = SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE | SUPPORT_PLAY
Expand All @@ -39,6 +41,8 @@
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_HOST): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_MAX_VOLUME, default=SUPPORTED_MAX_VOLUME):
vol.All(vol.Coerce(int), vol.Range(min=1, max=SUPPORTED_MAX_VOLUME)),
vol.Optional(CONF_SOURCES, default=DEFAULT_SOURCES):
{cv.string: cv.string},
vol.Optional(CONF_ZONE2, default=False): cv.boolean,
Expand All @@ -57,7 +61,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
try:
hosts.append(OnkyoDevice(
eiscp.eISCP(host), config.get(CONF_SOURCES),
name=config.get(CONF_NAME)))
name=config.get(CONF_NAME),
max_volume=config.get(CONF_MAX_VOLUME),
))
KNOWN_HOSTS.append(host)

# Add Zone2 if configured
Expand All @@ -80,14 +86,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class OnkyoDevice(MediaPlayerDevice):
"""Representation of an Onkyo device."""

def __init__(self, receiver, sources, name=None):
def __init__(self, receiver, sources, name=None,
max_volume=SUPPORTED_MAX_VOLUME):
"""Initialize the Onkyo Receiver."""
self._receiver = receiver
self._muted = False
self._volume = 0
self._pwstate = STATE_OFF
self._name = name or '{}_{}'.format(
receiver.info['model_name'], receiver.info['identifier'])
self._max_volume = max_volume
self._current_source = None
self._source_list = list(sources.values())
self._source_mapping = sources
Expand Down Expand Up @@ -141,7 +149,7 @@ def update(self):
self._current_source = '_'.join(
[i for i in current_source_tuples[1]])
self._muted = bool(mute_raw[1] == 'on')
self._volume = volume_raw[1] / 80.0
self._volume = volume_raw[1] / self._max_volume

@property
def name(self):
Expand Down Expand Up @@ -183,8 +191,13 @@ def turn_off(self):
self.command('system-power standby')

def set_volume_level(self, volume):
"""Set volume level, input is range 0..1. Onkyo ranges from 1-80."""
self.command('volume {}'.format(int(volume*80)))
"""
Set volume level, input is range 0..1.

Onkyo ranges from 1-80 however 80 is usually far too loud
so allow the user to specify the upper range with CONF_MAX_VOLUME
"""
self.command('volume {}'.format(int(volume * self._max_volume)))

def mute_volume(self, mute):
"""Mute (true) or unmute (false) media player."""
Expand Down