From cdbecffb52a6291f0662a41353aa0c7bff94b17a Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 23 Feb 2024 13:11:49 -0600 Subject: [PATCH 1/5] add fast forward and rewind support in companion protocol --- pyatv/core/facade.py | 10 ++++++++++ pyatv/interface.py | 10 ++++++++++ pyatv/protocols/companion/__init__.py | 14 +++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/pyatv/core/facade.py b/pyatv/core/facade.py index 755e72e4e..700e8b759 100644 --- a/pyatv/core/facade.py +++ b/pyatv/core/facade.py @@ -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.""" diff --git a/pyatv/interface.py b/pyatv/interface.py index 4affd4bb9..5edc11dea 100644 --- a/pyatv/interface.py +++ b/pyatv/interface.py @@ -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): diff --git a/pyatv/protocols/companion/__init__.py b/pyatv/protocols/companion/__init__.py index ad7e5f58d..f9f20d369 100644 --- a/pyatv/protocols/companion/__init__.py +++ b/pyatv/protocols/companion/__init__.py @@ -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( @@ -140,6 +142,8 @@ class MediaControlFlags(IntFlag): FeatureName.TextClear, FeatureName.TextAppend, FeatureName.TextSet, + FeatureName.FastForward, + FeatureName.Rewind ] # Remote control (playback, i.e. Media Control) + list(MEDIA_CONTROL_MAP.keys()) @@ -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) @@ -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) \ No newline at end of file From 00356b3c87fd4885f7a663acca62e23a403ca1d5 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 26 Feb 2024 12:32:11 -0600 Subject: [PATCH 2/5] add fast forward and remote support for companion protocol --- pyatv/const.py | 8 ++++++-- pyatv/protocols/companion/__init__.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pyatv/const.py b/pyatv/const.py index 2cdc5394e..ab4da9fa4 100644 --- a/pyatv/const.py +++ b/pyatv/const.py @@ -5,7 +5,7 @@ MAJOR_VERSION = "0" MINOR_VERSION = "14" -PATCH_VERSION = "5" +PATCH_VERSION = "4" __short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}" __version__ = f"{__short_version__}.{PATCH_VERSION}" @@ -305,6 +305,10 @@ class FeatureName(Enum): WakeUp = 18 """Wake up device (deprecated; use Power.turn_on).""" + FastForward = 63 + + Rewind = 64 + SkipForward = 36 """Skip forward a time interval.""" @@ -432,4 +436,4 @@ class FeatureName(Enum): """Input text into virtual keyboard.""" TextSet = 54 - """Replace text in virtual keyboard.""" + """Replace text in virtual keyboard.""" \ No newline at end of file diff --git a/pyatv/protocols/companion/__init__.py b/pyatv/protocols/companion/__init__.py index f9f20d369..78dd0b09b 100644 --- a/pyatv/protocols/companion/__init__.py +++ b/pyatv/protocols/companion/__init__.py @@ -128,6 +128,8 @@ class MediaControlFlags(IntFlag): FeatureName.Left, FeatureName.Right, FeatureName.Select, + FeatureName.FastForward, + FeatureName.Rewind, FeatureName.Menu, FeatureName.Home, FeatureName.VolumeUp, @@ -142,8 +144,6 @@ class MediaControlFlags(IntFlag): FeatureName.TextClear, FeatureName.TextAppend, FeatureName.TextSet, - FeatureName.FastForward, - FeatureName.Rewind ] # Remote control (playback, i.e. Media Control) + list(MEDIA_CONTROL_MAP.keys()) From 3da65933480eb5616df654412c5a21153c949745 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 26 Feb 2024 12:48:11 -0600 Subject: [PATCH 3/5] add fast forward and remote support for companion protocol --- pyatv/const.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyatv/const.py b/pyatv/const.py index ab4da9fa4..a0a45f7f8 100644 --- a/pyatv/const.py +++ b/pyatv/const.py @@ -5,7 +5,7 @@ MAJOR_VERSION = "0" MINOR_VERSION = "14" -PATCH_VERSION = "4" +PATCH_VERSION = "5" __short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}" __version__ = f"{__short_version__}.{PATCH_VERSION}" @@ -306,8 +306,10 @@ class FeatureName(Enum): """Wake up device (deprecated; use Power.turn_on).""" FastForward = 63 + """Fast Forward.""" Rewind = 64 + """Rewind a time interval.""" SkipForward = 36 """Skip forward a time interval.""" @@ -436,4 +438,4 @@ class FeatureName(Enum): """Input text into virtual keyboard.""" TextSet = 54 - """Replace text in virtual keyboard.""" \ No newline at end of file + """Replace text in virtual keyboard.""" From fff92a65d3f5f0274296fa6ef48c2fbb0c295545 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 26 Feb 2024 12:50:15 -0600 Subject: [PATCH 4/5] add fast forward and remote support for companion protocol --- pyatv/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyatv/const.py b/pyatv/const.py index a0a45f7f8..da7db2498 100644 --- a/pyatv/const.py +++ b/pyatv/const.py @@ -309,7 +309,7 @@ class FeatureName(Enum): """Fast Forward.""" Rewind = 64 - """Rewind a time interval.""" + """Rewind.""" SkipForward = 36 """Skip forward a time interval.""" From ba3cb5f69c9c711c0f2f5a29bd926a2c9dda8fe9 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 26 Feb 2024 16:30:55 -0600 Subject: [PATCH 5/5] add fast forward and rewind constants to media control feature array for tests --- tests/protocols/companion/test_companion_functional.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/protocols/companion/test_companion_functional.py b/tests/protocols/companion/test_companion_functional.py index afd87a933..388363e64 100644 --- a/tests/protocols/companion/test_companion_functional.py +++ b/tests/protocols/companion/test_companion_functional.py @@ -39,6 +39,8 @@ FeatureName.Previous, FeatureName.SkipForward, FeatureName.SkipBackward, + FeatureName.FastForward, + FeatureName.Rewind, FeatureName.Volume, FeatureName.SetVolume, ]