diff --git a/homeassistant/components/media_player/onkyo.py b/homeassistant/components/media_player/onkyo.py index 587031653852dc..b11a40901774e7 100644 --- a/homeassistant/components/media_player/onkyo.py +++ b/homeassistant/components/media_player/onkyo.py @@ -13,7 +13,8 @@ from homeassistant.components.media_player import ( SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, - SUPPORT_SELECT_SOURCE, SUPPORT_PLAY, MediaPlayerDevice, PLATFORM_SCHEMA) + SUPPORT_VOLUME_STEP, SUPPORT_SELECT_SOURCE, SUPPORT_PLAY, + MediaPlayerDevice, PLATFORM_SCHEMA) from homeassistant.const import (STATE_OFF, STATE_ON, CONF_HOST, CONF_NAME) import homeassistant.helpers.config_validation as cv @@ -27,7 +28,8 @@ DEFAULT_NAME = 'Onkyo Receiver' SUPPORT_ONKYO = SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \ - SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE | SUPPORT_PLAY + SUPPORT_VOLUME_STEP | SUPPORT_TURN_ON | SUPPORT_TURN_OFF | \ + SUPPORT_SELECT_SOURCE | SUPPORT_PLAY KNOWN_HOSTS = [] # type: List[str] DEFAULT_SOURCES = {'tv': 'TV', 'bd': 'Bluray', 'game': 'Game', 'aux1': 'Aux1', @@ -82,6 +84,8 @@ class OnkyoDevice(MediaPlayerDevice): def __init__(self, receiver, sources, name=None): """Initialize the Onkyo Receiver.""" + from concurrent.futures import ThreadPoolExecutor + self._receiver = receiver self._muted = False self._volume = 0 @@ -93,7 +97,9 @@ def __init__(self, receiver, sources, name=None): self._source_mapping = sources self._reverse_mapping = {value: key for key, value in sources.items()} - def command(self, command): + self._executor = ThreadPoolExecutor(max_workers=1) + + def execute_command(self, command): """Run an eiscp command and catch connection errors.""" try: result = self._receiver.command(command) @@ -107,6 +113,11 @@ def command(self, command): return False return result + def command(self, command): + """Add a command to the execution queue and wait for a result.""" + future = self._executor.submit(self.execute_command, command) + return future.result() + def update(self): """Get the latest state from the device.""" status = self.command('system-power query') @@ -186,6 +197,14 @@ 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))) + def volume_up(self): + """Increase volume by 1 step.""" + self.command('volume level-up') + + def volume_down(self): + """Decrease volume by 1 step.""" + self.command('volume level-down') + def mute_volume(self, mute): """Mute (true) or unmute (false) media player.""" if mute: @@ -251,6 +270,14 @@ def set_volume_level(self, volume): """Set volume level, input is range 0..1. Onkyo ranges from 1-80.""" self.command('zone2.volume={}'.format(int(volume*80))) + def volume_up(self): + """Increase volume by 1 step.""" + self.command('zone2.volume=level-up') + + def volume_down(self): + """Decrease volume by 1 step.""" + self.command('zone2.volume=level-down') + def mute_volume(self, mute): """Mute (true) or unmute (false) media player.""" if mute: