Fix pioneer volume when using onkyo component (#27218)

* Fix Onkyo when using pioneer AV receiver so it can use max volume of 164

* Update media_player.py

Change to make receiver max volume configurable

* Update manifest.json

Update to latest onkyo-eiscp with a fix required for Pionner AVR

* Fix Onkyo when using pioneer AV receiver so it can use max volume of 164

* Fix Onkyo when using pioneer AV receiver so it can use max volume of 164

* Format

* Requirements all

* Fix CI errors

* Black
This commit is contained in:
foxy82 2019-10-13 09:59:35 +01:00 committed by Martin Hjelmare
parent 066f2db602
commit 7aae106525
3 changed files with 61 additions and 14 deletions

View File

@ -3,7 +3,7 @@
"name": "Onkyo", "name": "Onkyo",
"documentation": "https://www.home-assistant.io/integrations/onkyo", "documentation": "https://www.home-assistant.io/integrations/onkyo",
"requirements": [ "requirements": [
"onkyo-eiscp==1.2.4" "onkyo-eiscp==1.2.7"
], ],
"dependencies": [], "dependencies": [],
"codeowners": [] "codeowners": []

View File

@ -31,9 +31,11 @@ _LOGGER = logging.getLogger(__name__)
CONF_SOURCES = "sources" CONF_SOURCES = "sources"
CONF_MAX_VOLUME = "max_volume" CONF_MAX_VOLUME = "max_volume"
CONF_RECEIVER_MAX_VOLUME = "receiver_max_volume"
DEFAULT_NAME = "Onkyo Receiver" DEFAULT_NAME = "Onkyo Receiver"
SUPPORTED_MAX_VOLUME = 80 SUPPORTED_MAX_VOLUME = 100
DEFAULT_RECEIVER_MAX_VOLUME = 80
SUPPORT_ONKYO = ( SUPPORT_ONKYO = (
SUPPORT_VOLUME_SET SUPPORT_VOLUME_SET
@ -77,8 +79,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
vol.Optional(CONF_HOST): cv.string, vol.Optional(CONF_HOST): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_MAX_VOLUME, default=SUPPORTED_MAX_VOLUME): vol.All( vol.Optional(CONF_MAX_VOLUME, default=SUPPORTED_MAX_VOLUME): vol.All(
vol.Coerce(int), vol.Range(min=1, max=SUPPORTED_MAX_VOLUME) vol.Coerce(int), vol.Range(min=1, max=100)
), ),
vol.Optional(
CONF_RECEIVER_MAX_VOLUME, default=DEFAULT_RECEIVER_MAX_VOLUME
): vol.All(vol.Coerce(int), vol.Range(min=0)),
vol.Optional(CONF_SOURCES, default=DEFAULT_SOURCES): {cv.string: cv.string}, vol.Optional(CONF_SOURCES, default=DEFAULT_SOURCES): {cv.string: cv.string},
} }
) )
@ -163,6 +168,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
config.get(CONF_SOURCES), config.get(CONF_SOURCES),
name=config.get(CONF_NAME), name=config.get(CONF_NAME),
max_volume=config.get(CONF_MAX_VOLUME), max_volume=config.get(CONF_MAX_VOLUME),
receiver_max_volume=config.get(CONF_RECEIVER_MAX_VOLUME),
) )
) )
KNOWN_HOSTS.append(host) KNOWN_HOSTS.append(host)
@ -178,6 +184,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
receiver, receiver,
config.get(CONF_SOURCES), config.get(CONF_SOURCES),
name=f"{config[CONF_NAME]} Zone 2", name=f"{config[CONF_NAME]} Zone 2",
max_volume=config.get(CONF_MAX_VOLUME),
receiver_max_volume=config.get(CONF_RECEIVER_MAX_VOLUME),
) )
) )
# Add Zone3 if available # Add Zone3 if available
@ -189,6 +197,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
receiver, receiver,
config.get(CONF_SOURCES), config.get(CONF_SOURCES),
name=f"{config[CONF_NAME]} Zone 3", name=f"{config[CONF_NAME]} Zone 3",
max_volume=config.get(CONF_MAX_VOLUME),
receiver_max_volume=config.get(CONF_RECEIVER_MAX_VOLUME),
) )
) )
except OSError: except OSError:
@ -204,7 +214,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
class OnkyoDevice(MediaPlayerDevice): class OnkyoDevice(MediaPlayerDevice):
"""Representation of an Onkyo device.""" """Representation of an Onkyo device."""
def __init__(self, receiver, sources, name=None, max_volume=SUPPORTED_MAX_VOLUME): def __init__(
self,
receiver,
sources,
name=None,
max_volume=SUPPORTED_MAX_VOLUME,
receiver_max_volume=DEFAULT_RECEIVER_MAX_VOLUME,
):
"""Initialize the Onkyo Receiver.""" """Initialize the Onkyo Receiver."""
self._receiver = receiver self._receiver = receiver
self._muted = False self._muted = False
@ -214,6 +231,7 @@ class OnkyoDevice(MediaPlayerDevice):
name or f"{receiver.info['model_name']}_{receiver.info['identifier']}" name or f"{receiver.info['model_name']}_{receiver.info['identifier']}"
) )
self._max_volume = max_volume self._max_volume = max_volume
self._receiver_max_volume = receiver_max_volume
self._current_source = None self._current_source = None
self._source_list = list(sources.values()) self._source_list = list(sources.values())
self._source_mapping = sources self._source_mapping = sources
@ -270,7 +288,10 @@ class OnkyoDevice(MediaPlayerDevice):
del self._attributes[ATTR_PRESET] del self._attributes[ATTR_PRESET]
self._muted = bool(mute_raw[1] == "on") self._muted = bool(mute_raw[1] == "on")
self._volume = volume_raw[1] / self._max_volume # AMP_VOL/MAX_RECEIVER_VOL*(MAX_VOL/100)
self._volume = (
volume_raw[1] / self._receiver_max_volume * (self._max_volume / 100)
)
if not hdmi_out_raw: if not hdmi_out_raw:
return return
@ -324,10 +345,15 @@ class OnkyoDevice(MediaPlayerDevice):
""" """
Set volume level, input is range 0..1. Set volume level, input is range 0..1.
Onkyo ranges from 1-80 however 80 is usually far too loud However full volume on the amp is usually far too loud so allow the user to specify the upper range
so allow the user to specify the upper range with CONF_MAX_VOLUME with CONF_MAX_VOLUME. we change as per max_volume set by user. This means that if max volume is 80 then full
volume in HA will give 80% volume on the receiver. Then we convert
that to the correct scale for the receiver.
""" """
self.command(f"volume {int(volume * self._max_volume)}") # HA_VOL * (MAX VOL / 100) * MAX_RECEIVER_VOL
self.command(
f"volume {int(volume * (self._max_volume / 100) * self._receiver_max_volume)}"
)
def volume_up(self): def volume_up(self):
"""Increase volume by 1 step.""" """Increase volume by 1 step."""
@ -368,11 +394,19 @@ class OnkyoDevice(MediaPlayerDevice):
class OnkyoDeviceZone(OnkyoDevice): class OnkyoDeviceZone(OnkyoDevice):
"""Representation of an Onkyo device's extra zone.""" """Representation of an Onkyo device's extra zone."""
def __init__(self, zone, receiver, sources, name=None): def __init__(
self,
zone,
receiver,
sources,
name=None,
max_volume=SUPPORTED_MAX_VOLUME,
receiver_max_volume=DEFAULT_RECEIVER_MAX_VOLUME,
):
"""Initialize the Zone with the zone identifier.""" """Initialize the Zone with the zone identifier."""
self._zone = zone self._zone = zone
self._supports_volume = True self._supports_volume = True
super().__init__(receiver, sources, name) super().__init__(receiver, sources, name, max_volume, receiver_max_volume)
def update(self): def update(self):
"""Get the latest state from the device.""" """Get the latest state from the device."""
@ -419,7 +453,10 @@ class OnkyoDeviceZone(OnkyoDevice):
elif ATTR_PRESET in self._attributes: elif ATTR_PRESET in self._attributes:
del self._attributes[ATTR_PRESET] del self._attributes[ATTR_PRESET]
if self._supports_volume: if self._supports_volume:
self._volume = volume_raw[1] / 80.0 # AMP_VOL/MAX_RECEIVER_VOL*(MAX_VOL/100)
self._volume = (
volume_raw[1] / self._receiver_max_volume * (self._max_volume / 100)
)
@property @property
def supported_features(self): def supported_features(self):
@ -433,8 +470,18 @@ class OnkyoDeviceZone(OnkyoDevice):
self.command(f"zone{self._zone}.power=standby") self.command(f"zone{self._zone}.power=standby")
def set_volume_level(self, volume): def set_volume_level(self, volume):
"""Set volume level, input is range 0..1. Onkyo ranges from 1-80.""" """
self.command(f"zone{self._zone}.volume={int(volume * 80)}") Set volume level, input is range 0..1.
However full volume on the amp is usually far too loud so allow the user to specify the upper range
with CONF_MAX_VOLUME. we change as per max_volume set by user. This means that if max volume is 80 then full
volume in HA will give 80% volume on the receiver. Then we convert
that to the correct scale for the receiver.
"""
# HA_VOL * (MAX VOL / 100) * MAX_RECEIVER_VOL
self.command(
f"zone{self._zone}.volume={int(volume * (self._max_volume / 100) * self._receiver_max_volume)}"
)
def volume_up(self): def volume_up(self):
"""Increase volume by 1 step.""" """Increase volume by 1 step."""

View File

@ -890,7 +890,7 @@ oauth2client==4.0.0
oemthermostat==1.1 oemthermostat==1.1
# homeassistant.components.onkyo # homeassistant.components.onkyo
onkyo-eiscp==1.2.4 onkyo-eiscp==1.2.7
# homeassistant.components.onvif # homeassistant.components.onvif
onvif-zeep-async==0.2.0 onvif-zeep-async==0.2.0