From 27215384ddeec2e8e95bf3fafb4257c98c87d6a9 Mon Sep 17 00:00:00 2001 From: Toby Scholz Date: Sun, 15 Mar 2026 15:26:00 -0400 Subject: [PATCH 1/3] Fixed Playing and Pausing when in mode internet radio --- afsapi/api.py | 12 ++++++++++++ afsapi/models.py | 1 + 2 files changed, 13 insertions(+) diff --git a/afsapi/api.py b/afsapi/api.py index 21c7b3c..78e521d 100644 --- a/afsapi/api.py +++ b/afsapi/api.py @@ -519,18 +519,30 @@ async def play_control(self, value: t.Union[PlayControl, int]) -> t.Optional[boo async def play(self) -> t.Optional[bool]: """Play media.""" + mode = await self.get_mode() + if mode.label == "Internet radio": + return await self.play_control(PlayControl.STOP) return await self.play_control(PlayControl.PLAY) async def pause(self) -> t.Optional[bool]: """Pause playing.""" + mode = await self.get_mode() + if mode.label == "Internet radio": + return await self.play_control(PlayControl.STOP) return await self.play_control(PlayControl.PAUSE) async def forward(self) -> t.Optional[bool]: """Next media.""" + mode = await self.get_mode() + if mode.label == "Internet radio": + return None #Not supported return await self.play_control(PlayControl.NEXT) async def rewind(self) -> t.Optional[bool]: """Previous media.""" + mode = await self.get_mode() + if mode.label == "Internet radio": + return None #Not supported return await self.play_control(PlayControl.PREV) async def get_equalisers(self) -> t.List[Equaliser]: diff --git a/afsapi/models.py b/afsapi/models.py index e87c543..f341f61 100644 --- a/afsapi/models.py +++ b/afsapi/models.py @@ -11,6 +11,7 @@ class PlayState(IntEnum): class PlayControl(IntEnum): + STOP = 0 PLAY = 1 PAUSE = 2 NEXT = 3 From fd6c8f0ac143aebdf68485d5167f8e6bba21d048 Mon Sep 17 00:00:00 2001 From: Toby Scholz Date: Sun, 22 Mar 2026 16:11:16 -0400 Subject: [PATCH 2/3] Remove override in play / pause / forward / rewind methods --- afsapi/api.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/afsapi/api.py b/afsapi/api.py index 78e521d..21c7b3c 100644 --- a/afsapi/api.py +++ b/afsapi/api.py @@ -519,30 +519,18 @@ async def play_control(self, value: t.Union[PlayControl, int]) -> t.Optional[boo async def play(self) -> t.Optional[bool]: """Play media.""" - mode = await self.get_mode() - if mode.label == "Internet radio": - return await self.play_control(PlayControl.STOP) return await self.play_control(PlayControl.PLAY) async def pause(self) -> t.Optional[bool]: """Pause playing.""" - mode = await self.get_mode() - if mode.label == "Internet radio": - return await self.play_control(PlayControl.STOP) return await self.play_control(PlayControl.PAUSE) async def forward(self) -> t.Optional[bool]: """Next media.""" - mode = await self.get_mode() - if mode.label == "Internet radio": - return None #Not supported return await self.play_control(PlayControl.NEXT) async def rewind(self) -> t.Optional[bool]: """Previous media.""" - mode = await self.get_mode() - if mode.label == "Internet radio": - return None #Not supported return await self.play_control(PlayControl.PREV) async def get_equalisers(self) -> t.List[Equaliser]: From fa258e4908b97c30d509bc8419d3b85fa7fd0ae4 Mon Sep 17 00:00:00 2001 From: Toby Scholz Date: Sun, 22 Mar 2026 16:17:03 -0400 Subject: [PATCH 3/3] Added stop method and test for stop method --- afsapi/api.py | 4 ++++ async_tests.py | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/afsapi/api.py b/afsapi/api.py index 21c7b3c..b355a55 100644 --- a/afsapi/api.py +++ b/afsapi/api.py @@ -517,6 +517,10 @@ async def play_control(self, value: t.Union[PlayControl, int]) -> t.Optional[boo """ return await self.handle_set(API["control"], int(value)) + async def stop(self) -> t.Optional[bool]: + """Stop (and Start) media.""" + return await self.play_control(PlayControl.STOP) + async def play(self) -> t.Optional[bool]: """Play media.""" return await self.play_control(PlayControl.PLAY) diff --git a/async_tests.py b/async_tests.py index afeac4b..4316eb9 100644 --- a/async_tests.py +++ b/async_tests.py @@ -121,21 +121,28 @@ async def test_play() -> None: status = await afsapi.get_play_status() print("Status: %s" % status) + pause = await afsapi.pause() + print("Start play succeeded? - %s" % pause) + await asyncio.sleep(2) + start_play = await afsapi.play() print("Start play succeeded? - %s" % start_play) - await asyncio.sleep(1) + await asyncio.sleep(2) forward = await afsapi.forward() print("Next succeeded? - %s" % forward) - await asyncio.sleep(1) + await asyncio.sleep(2) rewind = await afsapi.rewind() print("Prev succeeded? - %s" % rewind) + stop = await afsapi.stop() + print("Stop play succeeded? - %s" % stop) + await asyncio.sleep(2) + except Exception: logging.error(traceback.format_exc()) - loop = asyncio.new_event_loop() loop.run_until_complete(test_sys())