Skip to content

Commit

Permalink
fix styling for 2462
Browse files Browse the repository at this point in the history
  • Loading branch information
thiccaxe authored and postlund committed Aug 5, 2024
1 parent 41b039f commit 7716858
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
17 changes: 13 additions & 4 deletions pyatv/protocols/companion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
# that pyatv supports).
PAIRING_WITH_PIN_SUPPORTED_MASK = 0x4000

# As seen in the TV Remote App
_DEFAULT_SKIP_TIME = 10

# pylint: disable=invalid-name
Expand Down Expand Up @@ -342,18 +343,26 @@ async def previous(self) -> None:
await self.api.mediacontrol_command(MediaControlCommand.PreviousTrack)

async def skip_forward(self, time_interval: float = 0.0) -> None:
"""Skip forward a time interval."""
await self.api.mediacontrol_command(
MediaControlCommand.SkipBy,
{"_skpS": float(time_interval if time_interval > 0 else _DEFAULT_SKIP_TIME)}
{
"_skpS": float(
time_interval if time_interval > 0 else _DEFAULT_SKIP_TIME
)
},
)

async def skip_backward(self, time_interval: float = 0.0) -> None:
"""Skip forward a time interval."""
# float cast: opack fails with negative integers
await self.api.mediacontrol_command(
MediaControlCommand.SkipBy,
{ "_skpS":
float(-time_interval if time_interval > 0 else -_DEFAULT_SKIP_TIME)
}
{
"_skpS": float(
-time_interval if time_interval > 0 else -_DEFAULT_SKIP_TIME
)
},
)

async def channel_up(self) -> None:
Expand Down
12 changes: 8 additions & 4 deletions pyatv/protocols/dmap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,10 @@ async def skip_forward(self, time_interval: float = 0.0) -> None:
"""
current_position = (await self.apple_tv.playstatus()).position
if current_position:
await self.set_position(current_position +
(int(time_interval) if time_interval > 0 else _DEFAULT_SKIP_TIME))
await self.set_position(
current_position
+ (int(time_interval) if time_interval > 0 else _DEFAULT_SKIP_TIME)
)

async def skip_backward(self, time_interval: float = 0.0) -> None:
"""Skip backwards a time interval.
Expand All @@ -370,8 +372,10 @@ async def skip_backward(self, time_interval: float = 0.0) -> None:
"""
current_position = (await self.apple_tv.playstatus()).position
if current_position:
await self.set_position(current_position -
(int(time_interval) if time_interval > 0 else _DEFAULT_SKIP_TIME))
await self.set_position(
current_position
- (int(time_interval) if time_interval > 0 else _DEFAULT_SKIP_TIME)
)

async def set_position(self, pos: int) -> None:
"""Seek in the current playing media."""
Expand Down
24 changes: 8 additions & 16 deletions tests/protocols/companion/test_companion_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from pyatv.protocols.companion.api import SystemStatus

from tests.fake_device.companion import (
INITIAL_DURATION,
INITIAL_RTI_TEXT,
INITIAL_VOLUME,
INITIAL_DURATION,
VOLUME_STEP,
CompanionServiceFlags,
)
Expand Down Expand Up @@ -217,37 +217,29 @@ async def test_remote_control_buttons(companion_client, companion_state, button)
await getattr(companion_client.remote_control, button)()
assert companion_state.latest_button == button


async def test_remote_control_skip_forward_backward(companion_client, companion_state):
duration = companion_state.duration
await companion_client.remote_control.skip_forward()
await until(
lambda: math.isclose(companion_state.duration, duration + 10)
)
await until(lambda: math.isclose(companion_state.duration, duration + 10))

duration = companion_state.duration
await companion_client.remote_control.skip_backward()
await until(
lambda: math.isclose(companion_state.duration, duration - 10)
)
await until(lambda: math.isclose(companion_state.duration, duration - 10))

duration = companion_state.duration
await companion_client.remote_control.skip_forward(10.5)
await until(
lambda: math.isclose(companion_state.duration, duration + 10.5)
)
await until(lambda: math.isclose(companion_state.duration, duration + 10.5))

duration = companion_state.duration
await companion_client.remote_control.skip_backward(7.3)
await until(
lambda: math.isclose(companion_state.duration, duration - 7.3)
)
await until(lambda: math.isclose(companion_state.duration, duration - 7.3))

# "From beginning"
duration = companion_state.duration
await companion_client.remote_control.skip_backward(9999999.0)
await until(
lambda: math.isclose(companion_state.duration, 0)
)
await until(lambda: math.isclose(companion_state.duration, 0))


async def test_audio_set_volume(companion_client, companion_state, companion_usecase):
await until(lambda: companion_client.audio.volume, INITIAL_VOLUME)
Expand Down

0 comments on commit 7716858

Please sign in to comment.