Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added additional commands (telnet and http protocols) : DPAD and menus #36

Merged
merged 7 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .idea/misc.xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert this once merged. Python 3.11 is required to embedd it in the R2 firmware.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions intg-denonavr/avr.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

DISCOVERY_AFTER_CONNECTION_ERRORS = 10

AVR_COMMAND_URL = "/goform/formiPhoneAppDirect.xml"


class Events(IntEnum):
"""Internal driver events."""
Expand Down Expand Up @@ -716,6 +718,107 @@ async def select_sound_mode(self, sound_mode: str | None) -> ucapi.StatusCodes:
return ucapi.StatusCodes.BAD_REQUEST
await self._receiver.async_set_sound_mode(sound_mode)

@async_handle_denonlib_errors
async def cursor_up(self) -> ucapi.StatusCodes:
"""Send cursor up command to AVR."""
# TODO : to be updated when PR will be released https://github.com/ol-iver/denonavr/pull/290
if self._use_telnet:
await self._receiver.async_send_telnet_commands("MNCUP")
else:
await self._receiver.async_get_command(AVR_COMMAND_URL + "?MNCUP")

@async_handle_denonlib_errors
async def cursor_down(self) -> ucapi.StatusCodes:
"""Send cursor down command to AVR."""
# TODO : to be updated when PR will be released https://github.com/ol-iver/denonavr/pull/290
if self._use_telnet:
await self._receiver.async_send_telnet_commands("MNCDN")
else:
await self._receiver.async_get_command(AVR_COMMAND_URL + "?MNCDN")

@async_handle_denonlib_errors
async def cursor_left(self) -> ucapi.StatusCodes:
"""Send cursor left command to AVR."""
# TODO : to be updated when PR will be released https://github.com/ol-iver/denonavr/pull/290
if self._use_telnet:
await self._receiver.async_send_telnet_commands("MNCLT")
else:
await self._receiver.async_get_command(AVR_COMMAND_URL + "?MNCLT")

@async_handle_denonlib_errors
async def cursor_right(self) -> ucapi.StatusCodes:
"""Send cursor right command to AVR."""
# TODO : to be updated when PR will be released https://github.com/ol-iver/denonavr/pull/290
if self._use_telnet:
await self._receiver.async_send_telnet_commands("MNCRT")
else:
await self._receiver.async_get_command(AVR_COMMAND_URL + "?MNCRT")

@async_handle_denonlib_errors
async def cursor_enter(self) -> ucapi.StatusCodes:
"""Send cursor enter command to AVR."""
# TODO : to be updated when PR will be released https://github.com/ol-iver/denonavr/pull/290
if self._use_telnet:
await self._receiver.async_send_telnet_commands("MNENT")
else:
await self._receiver.async_get_command(AVR_COMMAND_URL + "?MNENT")

@async_handle_denonlib_errors
async def info(self) -> ucapi.StatusCodes:
"""Send info OSD command command to AVR."""
# TODO : to be updated when PR will be released https://github.com/ol-iver/denonavr/pull/290
if self._use_telnet:
await self._receiver.async_send_telnet_commands("MNINF")
else:
await self._receiver.async_get_command(AVR_COMMAND_URL + "?MNINF")

@async_handle_denonlib_errors
async def options(self) -> ucapi.StatusCodes:
"""Send options menu command to AVR."""
# TODO : to be updated when PR will be released https://github.com/ol-iver/denonavr/pull/290
if self._use_telnet:
await self._receiver.async_send_telnet_commands("MNOPT")
else:
await self._receiver.async_get_command(AVR_COMMAND_URL + "?MNOPT")

@async_handle_denonlib_errors
async def back(self) -> ucapi.StatusCodes:
"""Send back command to AVR."""
# TODO : to be updated when PR will be released https://github.com/ol-iver/denonavr/pull/290
if self._use_telnet:
await self._receiver.async_send_telnet_commands("MNRTN")
else:
await self._receiver.async_get_command(AVR_COMMAND_URL + "?MNRTN")

@async_handle_denonlib_errors
async def setup_open(self) -> ucapi.StatusCodes:
"""Send open setup menu command to AVR."""
# TODO : to be updated when PR will be released https://github.com/ol-iver/denonavr/pull/290
if self._use_telnet:
await self._receiver.async_send_telnet_commands("MNMEN ON")
else:
await self._receiver.async_get_command(AVR_COMMAND_URL + "?MNMEN%20ON")

@async_handle_denonlib_errors
async def setup_close(self) -> ucapi.StatusCodes:
"""Send close menu command to AVR."""
# TODO : to be updated when PR will be released https://github.com/ol-iver/denonavr/pull/290
if self._use_telnet:
await self._receiver.async_send_telnet_commands("MNMEN OFF")
else:
await self._receiver.async_get_command(AVR_COMMAND_URL + "?MNMEN%20OFF")

@async_handle_denonlib_errors
async def setup(self) -> ucapi.StatusCodes:
"""Send toggle open/close menu command to AVR."""
# TODO : to be updated when PR will be released https://github.com/ol-iver/denonavr/pull/290
# Using http get as the telnet commands won't return any values
res = await self._receiver.async_get_command(AVR_COMMAND_URL + "?MNMEN?")
if res is not None and res == "MNMEN ON":
await self.setup_close()
else:
await self.setup_open()

def _increase_expected_volume(self):
"""Without telnet, increase expected volume and send update event."""
if not self._use_telnet or self._expected_volume is None:
Expand Down
22 changes: 22 additions & 0 deletions intg-denonavr/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def __init__(self, device: AvrDevice, receiver: avr.DenonDevice):
Features.MEDIA_IMAGE_URL,
Features.MEDIA_TYPE,
Features.SELECT_SOURCE,
Features.DPAD,
Features.MENU,
Features.CONTEXT_MENU,
Features.INFO,
]
attributes = {
Attributes.STATE: States.UNAVAILABLE,
Expand Down Expand Up @@ -112,6 +116,24 @@ async def command(self, cmd_id: str, params: dict[str, Any] | None = None) -> St
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()
else:
return StatusCodes.NOT_IMPLEMENTED

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pyee>=9.0
denonavr~=0.11.4
ucapi==0.1.3
denonavr~=0.11.6
ucapi==0.1.7
Loading