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

add fast forward and rewind support for companion protocol #2363

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions pyatv/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ class FeatureName(Enum):
WakeUp = 18
"""Wake up device (deprecated; use Power.turn_on)."""

FastForward = 63
"""Fast Forward."""

Rewind = 64
"""Rewind."""

SkipForward = 36
"""Skip forward a time interval."""

Expand Down
10 changes: 10 additions & 0 deletions pyatv/core/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ async def screensaver(self) -> None:
"""Activate screen saver.."""
return await self.relay("screensaver")()

@shield.guard
async def fast_forward(self) -> None:
"""Fast Forward.."""
return await self.relay("fast_forward")()

@shield.guard
async def rewind(self) -> None:
"""Rewind.."""
return await self.relay("rewind")()


class FacadeMetadata(Relayer, interface.Metadata):
"""Facade implementation for retrieving metadata from an Apple TV."""
Expand Down
10 changes: 10 additions & 0 deletions pyatv/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,16 @@ async def screensaver(self) -> None:
"""Activate screen saver.."""
raise exceptions.NotSupportedError()

@feature(63, "FastForward", "Fast Forward.")
async def fast_forward(self, action: InputAction = InputAction.SingleTap) -> None:
"""Press key fast forward."""
raise exceptions.NotSupportedError()

@feature(64, "Rewind", "Rewind.")
async def rewind(self, action: InputAction = InputAction.SingleTap) -> None:
"""Press key rewind."""
raise exceptions.NotSupportedError()


# TODO: Should be made into a dataclass when support for 3.6 is dropped
class Playing(ABC):
Expand Down
14 changes: 13 additions & 1 deletion pyatv/protocols/companion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class MediaControlFlags(IntFlag):
FeatureName.SetVolume: MediaControlFlags.Volume,
FeatureName.SkipForward: MediaControlFlags.SkipForward,
FeatureName.SkipBackward: MediaControlFlags.SkipBackward,
FeatureName.FastForward: MediaControlFlags.FastForward,
FeatureName.Rewind: MediaControlFlags.Rewind
}

SUPPORTED_FEATURES = set(
Expand All @@ -126,6 +128,8 @@ class MediaControlFlags(IntFlag):
FeatureName.Left,
FeatureName.Right,
FeatureName.Select,
FeatureName.FastForward,
FeatureName.Rewind,
FeatureName.Menu,
FeatureName.Home,
FeatureName.VolumeUp,
Expand Down Expand Up @@ -334,6 +338,14 @@ async def previous(self) -> None:
"""Press key previous."""
await self.api.mediacontrol_command(MediaControlCommand.PreviousTrack)

async def fast_forward(self) -> None:
"""Press key fast forward."""
await self.api.mediacontrol_command(MediaControlCommand.FastForwardBegin)

async def rewind(self) -> None:
"""Press key rewind."""
await self.api.mediacontrol_command(MediaControlCommand.RewindBegin)

async def channel_up(self) -> None:
"""Select next channel."""
await self._press_button(HidCommand.ChannelIncrement)
Expand Down Expand Up @@ -590,4 +602,4 @@ def _device_info() -> Dict[str, Any]:

def pair(core: Core, **kwargs) -> PairingHandler:
"""Return pairing handler for protocol."""
return CompanionPairingHandler(core, **kwargs)
return CompanionPairingHandler(core, **kwargs)
2 changes: 2 additions & 0 deletions tests/protocols/companion/test_companion_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
FeatureName.Previous,
FeatureName.SkipForward,
FeatureName.SkipBackward,
FeatureName.FastForward,
FeatureName.Rewind,
FeatureName.Volume,
FeatureName.SetVolume,
]
Expand Down
Loading