Skip to content

Commit

Permalink
Added 2 other commands for FF/RW using companion protocol, which is b…
Browse files Browse the repository at this point in the history
…etter and works for all apps
  • Loading branch information
albaintor committed May 22, 2024
1 parent 9f21518 commit dbc825f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
13 changes: 12 additions & 1 deletion intg-appletv/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class SimpleCommands(str, Enum):
"""Skip forward a time interval."""
SKIP_BACKWARD = "SKIP_BACKWARD"
"""Skip forward a time interval."""
FAST_FORWARD_BEGIN = "FAST_FORWARD_BEGIN"
"""Fast forward using Companion protocol."""
REWIND_BEGIN = "REWIND_BEGIN"
"""Rewind using Companion protocol."""


@api.listens_to(ucapi.Events.CONNECT)
Expand Down Expand Up @@ -267,6 +271,10 @@ async def media_player_cmd_handler(
res = await device.skip_forward()
case SimpleCommands.SKIP_BACKWARD:
res = await device.skip_backward()
case SimpleCommands.FAST_FORWARD_BEGIN:
res = await device.fast_forward_companion()
case SimpleCommands.REWIND_BEGIN:
res = await device.rewind_companion()

return res

Expand Down Expand Up @@ -514,7 +522,10 @@ def _register_available_entities(identifier: str, name: str) -> bool:
SimpleCommands.TOP_MENU.value,
SimpleCommands.APP_SWITCHER.value,
SimpleCommands.SCREENSAVER.value,

SimpleCommands.SKIP_FORWARD.value,
SimpleCommands.SKIP_BACKWARD.value,
SimpleCommands.FAST_FORWARD_BEGIN.value,
SimpleCommands.REWIND_BEGIN.value
]
},
cmd_handler=media_player_cmd_handler,
Expand Down
20 changes: 20 additions & 0 deletions intg-appletv/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import pyatv
import pyatv.const
import ucapi
from pyatv.core.facade import FacadeRemoteControl

from config import AtvDevice, AtvProtocol
from pyatv.const import (
DeviceState,
Expand Down Expand Up @@ -581,6 +583,24 @@ async def rewind(self) -> ucapi.StatusCodes:
"""Long press key left for rewind."""
await self._atv.remote_control.left(InputAction.Hold)

@async_handle_atvlib_errors
async def fast_forward_companion(self) -> ucapi.StatusCodes:
"""Fast-forward using companion protocol."""
companion = cast(FacadeRemoteControl, self._atv.remote_control).get(Protocol.Companion)
if companion:
await companion.api.mediacontrol_command(command=MediaControlCommand.FastForwardBegin)
else:
await self._atv.remote_control.right(InputAction.Hold)

@async_handle_atvlib_errors
async def rewind_companion(self) -> ucapi.StatusCodes:
"""Rewind using companion protocol."""
companion = cast(FacadeRemoteControl, self._atv.remote_control).get(Protocol.Companion)
if companion:
await companion.api.mediacontrol_command(command=MediaControlCommand.RewindBegin)
else:
await self._atv.remote_control.left(InputAction.Hold)

@async_handle_atvlib_errors
async def next(self) -> ucapi.StatusCodes:
"""Press key next."""
Expand Down

0 comments on commit dbc825f

Please sign in to comment.