Skip to content

Commit

Permalink
Don't wait for confirmation when sending volume up/down telnet comman…
Browse files Browse the repository at this point in the history
…ds (#304)
  • Loading branch information
ol-iver authored Sep 22, 2024
1 parent 25622aa commit 2750370
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
43 changes: 27 additions & 16 deletions denonavr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ async def _async_establish_connection(self) -> None:
"PSREFLEV ?",
"PSDYNVOL ?",
"MS?",
skip_confirmation=True,
)

def _schedule_monitor(self) -> None:
Expand Down Expand Up @@ -731,35 +732,45 @@ async def _async_send_confirmation_callback(self, message: str) -> None:
self._send_confirmation_event.set()
_LOGGER.debug("Command %s confirmed", command)

async def _async_send_command(self, command: str) -> None:
async def _async_send_command(
self, command: str, skip_confirmation: bool = False
) -> None:
"""Send one telnet command to the receiver."""
async with self._send_lock:
self._send_confirmation_command = command
self._send_confirmation_event.clear()
if not skip_confirmation:
self._send_confirmation_command = command
self._send_confirmation_event.clear()
if not self.connected or not self.healthy:
raise AvrProcessingError(
f"Error sending command {command}. Telnet connected: "
f"{self.connected}, Connection healthy: {self.healthy}"
)
self._protocol.write(f"{command}\r")
try:
await asyncio.wait_for(
self._send_confirmation_event.wait(),
self._send_confirmation_timeout,
)
except asyncio.TimeoutError:
_LOGGER.info("Timeout waiting for confirmation of command: %s", command)
finally:
self._send_confirmation_command = ""
if not skip_confirmation:
try:
await asyncio.wait_for(
self._send_confirmation_event.wait(),
self._send_confirmation_timeout,
)
except asyncio.TimeoutError:
_LOGGER.info(
"Timeout waiting for confirmation of command: %s", command
)
finally:
self._send_confirmation_command = ""

async def async_send_commands(self, *commands: str) -> None:
async def async_send_commands(
self, *commands: str, skip_confirmation: bool = False
) -> None:
"""Send telnet commands to the receiver."""
for command in commands:
await self._async_send_command(command)
await self._async_send_command(command, skip_confirmation=skip_confirmation)

def send_commands(self, *commands: str) -> None:
def send_commands(self, *commands: str, skip_confirmation: bool = False) -> None:
"""Send telnet commands to the receiver."""
task = asyncio.create_task(self.async_send_commands(*commands))
task = asyncio.create_task(
self.async_send_commands(*commands, skip_confirmation=skip_confirmation)
)
self._send_tasks.add(task)
task.add_done_callback(self._send_tasks.discard)

Expand Down
8 changes: 5 additions & 3 deletions denonavr/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _schedule_netaudio_update(self) -> None:
def _update_netaudio(self) -> None:
"""Update netaudio information."""
if self._device.telnet_available:
self._device.telnet_api.send_commands("NSE")
self._device.telnet_api.send_commands("NSE", skip_confirmation=True)
self._schedule_netaudio_update()
else:
self._stop_media_update()
Expand Down Expand Up @@ -316,7 +316,9 @@ def _schedule_tuner_update(self) -> None:
def _update_tuner(self) -> None:
"""Update tuner information."""
if self._device.telnet_available:
self._device.telnet_api.send_commands("TFAN?", "TFANNAME?")
self._device.telnet_api.send_commands(
"TFAN?", "TFANNAME?", skip_confirmation=True
)
self._schedule_tuner_update()
else:
self._stop_media_update()
Expand Down Expand Up @@ -360,7 +362,7 @@ def _schedule_hdtuner_update(self) -> None:
def _update_hdtuner(self) -> None:
"""Update HD tuner information."""
if self._device.telnet_available:
self._device.telnet_api.send_commands("HD?")
self._device.telnet_api.send_commands("HD?", skip_confirmation=True)
self._schedule_hdtuner_update()
else:
self._stop_media_update()
Expand Down
4 changes: 2 additions & 2 deletions denonavr/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def async_volume_up(self) -> None:
"""Volume up receiver via HTTP get command."""
if self._device.telnet_available:
await self._device.telnet_api.async_send_commands(
self._device.telnet_commands.command_volume_up
self._device.telnet_commands.command_volume_up, skip_confirmation=True
)
else:
await self._device.api.async_get_command(
Expand All @@ -159,7 +159,7 @@ async def async_volume_down(self) -> None:
"""Volume down receiver via HTTP get command."""
if self._device.telnet_available:
await self._device.telnet_api.async_send_commands(
self._device.telnet_commands.command_volume_down
self._device.telnet_commands.command_volume_down, skip_confirmation=True
)
else:
await self._device.api.async_get_command(
Expand Down

0 comments on commit 2750370

Please sign in to comment.