Add support for max_volume (#13822)
* onkyo: add support for max volume range * onkyo: make flake8 happy * onkyo: fix PEP8 D205 on line 181 * onkyo: use range for max_volume configuration * onkyo: fix line too longpull/14279/merge
parent
f6e29a6647
commit
4d085882d5
|
@ -22,9 +22,11 @@ REQUIREMENTS = ['onkyo-eiscp==1.2.4']
|
|||
_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
|
||||
|
@ -39,6 +41,8 @@ DEFAULT_SOURCES = {'tv': 'TV', 'bd': 'Bluray', 'game': 'Game', 'aux1': 'Aux1',
|
|||
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,
|
||||
|
@ -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
|
||||
|
@ -80,7 +86,8 @@ 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
|
||||
|
@ -88,6 +95,7 @@ class OnkyoDevice(MediaPlayerDevice):
|
|||
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
|
||||
|
@ -141,7 +149,7 @@ class OnkyoDevice(MediaPlayerDevice):
|
|||
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):
|
||||
|
@ -183,8 +191,13 @@ class OnkyoDevice(MediaPlayerDevice):
|
|||
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."""
|
||||
|
|
Loading…
Reference in New Issue