diff --git a/intg-denonavr/avr.py b/intg-denonavr/avr.py index 28b2c1c..470c8bd 100644 --- a/intg-denonavr/avr.py +++ b/intg-denonavr/avr.py @@ -797,7 +797,7 @@ async def options(self) -> ucapi.StatusCodes: @async_handle_denonlib_errors async def output_monitor_1(self) -> ucapi.StatusCodes: - """Send cursor down command to AVR.""" + """Send set HDMI monitor out 1 command to AVR.""" if self._use_telnet: await self._receiver.async_send_telnet_commands("VSMONI1") else: @@ -805,7 +805,7 @@ async def output_monitor_1(self) -> ucapi.StatusCodes: @async_handle_denonlib_errors async def output_monitor_2(self) -> ucapi.StatusCodes: - """Send cursor down command to AVR.""" + """Send set HDMI monitor out 2 command to AVR.""" if self._use_telnet: await self._receiver.async_send_telnet_commands("VSMONI2") else: @@ -813,7 +813,7 @@ async def output_monitor_2(self) -> ucapi.StatusCodes: @async_handle_denonlib_errors async def output_monitor_auto(self) -> ucapi.StatusCodes: - """Send cursor down command to AVR.""" + """Send set HDMI monitor automatic detection command to AVR.""" if self._use_telnet: await self._receiver.async_send_telnet_commands("VSMONIAUTO") else: diff --git a/intg-denonavr/media_player.py b/intg-denonavr/media_player.py index c76d849..6a08001 100644 --- a/intg-denonavr/media_player.py +++ b/intg-denonavr/media_player.py @@ -6,6 +6,7 @@ """ import logging +from enum import Enum from typing import Any import avr @@ -33,6 +34,17 @@ } +class SimpleCommands(str, Enum): + """Additional simple commands of the Denon AVR not covered by media-player features.""" + + OUTPUT_1 = "OUTPUT_1" + """Set HDMI monitor out 1.""" + OUTPUT_2 = "OUTPUT_2" + """Set HDMI monitor out 2.""" + OUTPUT_AUTO = "OUTPUT_AUTO" + """Set HDMI monitor automatic detection.""" + + class DenonMediaPlayer(MediaPlayer): """Representation of a Denon Media Player entity.""" @@ -77,7 +89,11 @@ def __init__(self, device: AvrDevice, receiver: avr.DenonDevice): attributes[Attributes.SOUND_MODE] = "" attributes[Attributes.SOUND_MODE_LIST] = [] - self.simple_commands = ["OUTPUT_1", "OUTPUT_2", "OUTPUT_AUTO"] + self.simple_commands = [ + SimpleCommands.OUTPUT_1.value, + SimpleCommands.OUTPUT_2.value, + SimpleCommands.OUTPUT_AUTO.value, + ] options = {Options.SIMPLE_COMMANDS: self.simple_commands} @@ -90,7 +106,7 @@ def __init__(self, device: AvrDevice, receiver: avr.DenonDevice): options=options, ) - async def command(self, cmd_id: str, params: dict[str, Any] | None = None) -> StatusCodes: # pylint: disable=R0915 + async def command(self, cmd_id: str, params: dict[str, Any] | None = None) -> StatusCodes: """ Media-player entity command handler. @@ -106,54 +122,55 @@ async def command(self, cmd_id: str, params: dict[str, Any] | None = None) -> St _LOG.warning("No AVR instance for entity: %s", self.id) return StatusCodes.SERVICE_UNAVAILABLE - if cmd_id == Commands.PLAY_PAUSE: - res = await self._receiver.play_pause() - elif cmd_id == Commands.NEXT: - res = await self._receiver.next() - elif cmd_id == Commands.PREVIOUS: - res = await self._receiver.previous() - elif cmd_id == Commands.VOLUME: - res = await self._receiver.set_volume_level(params.get("volume")) - elif cmd_id == Commands.VOLUME_UP: - res = await self._receiver.volume_up() - elif cmd_id == Commands.VOLUME_DOWN: - res = await self._receiver.volume_down() - elif cmd_id == Commands.MUTE_TOGGLE: - res = await self._receiver.mute(not self.attributes[Attributes.MUTED]) - elif cmd_id == Commands.ON: - res = await self._receiver.power_on() - elif cmd_id == Commands.OFF: - res = await self._receiver.power_off() - elif cmd_id == Commands.SELECT_SOURCE: - res = await self._receiver.select_source(params.get("source")) - elif cmd_id == Commands.SELECT_SOUND_MODE: - res = await self._receiver.select_sound_mode(params.get("mode")) - elif cmd_id == Commands.CURSOR_UP: - res = await self._receiver.cursor_up() - elif cmd_id == Commands.CURSOR_DOWN: - res = await self._receiver.cursor_down() - elif cmd_id == Commands.CURSOR_LEFT: - res = await self._receiver.cursor_left() - elif cmd_id == Commands.CURSOR_RIGHT: - res = await self._receiver.cursor_right() - elif cmd_id == Commands.CURSOR_ENTER: - res = await self._receiver.cursor_enter() - elif cmd_id == Commands.BACK: - res = await self._receiver.back() - elif cmd_id == Commands.MENU: - res = await self._receiver.setup() - elif cmd_id == Commands.CONTEXT_MENU: - res = await self._receiver.options() - elif cmd_id == Commands.INFO: - res = await self._receiver.info() - elif cmd_id == "OUTPUT_1": - res = await self._receiver.output_monitor_1() - elif cmd_id == "OUTPUT_2": - res = await self._receiver.output_monitor_2() - elif cmd_id == "OUTPUT_AUTO": - res = await self._receiver.output_monitor_auto() - else: - return StatusCodes.NOT_IMPLEMENTED + match cmd_id: + case Commands.PLAY_PAUSE: + res = await self._receiver.play_pause() + case Commands.NEXT: + res = await self._receiver.next() + case Commands.PREVIOUS: + res = await self._receiver.previous() + case Commands.VOLUME: + res = await self._receiver.set_volume_level(params.get("volume")) + case Commands.VOLUME_UP: + res = await self._receiver.volume_up() + case Commands.VOLUME_DOWN: + res = await self._receiver.volume_down() + case Commands.MUTE_TOGGLE: + res = await self._receiver.mute(not self.attributes[Attributes.MUTED]) + case Commands.ON: + res = await self._receiver.power_on() + case Commands.OFF: + res = await self._receiver.power_off() + case Commands.SELECT_SOURCE: + res = await self._receiver.select_source(params.get("source")) + case Commands.SELECT_SOUND_MODE: + res = await self._receiver.select_sound_mode(params.get("mode")) + case Commands.CURSOR_UP: + res = await self._receiver.cursor_up() + case Commands.CURSOR_DOWN: + res = await self._receiver.cursor_down() + case Commands.CURSOR_LEFT: + res = await self._receiver.cursor_left() + case Commands.CURSOR_RIGHT: + res = await self._receiver.cursor_right() + case Commands.CURSOR_ENTER: + res = await self._receiver.cursor_enter() + case Commands.BACK: + res = await self._receiver.back() + case Commands.MENU: + res = await self._receiver.setup() + case Commands.CONTEXT_MENU: + res = await self._receiver.options() + case Commands.INFO: + res = await self._receiver.info() + case SimpleCommands.OUTPUT_1: + res = await self._receiver.output_monitor_1() + case SimpleCommands.OUTPUT_2: + res = await self._receiver.output_monitor_2() + case SimpleCommands.OUTPUT_AUTO: + res = await self._receiver.output_monitor_auto() + case _: + return StatusCodes.NOT_IMPLEMENTED return res