From 4386ab7868c0de69f57e7d47247f050029cdf134 Mon Sep 17 00:00:00 2001 From: Michel van de Wetering Date: Sat, 27 Jan 2024 18:42:17 +0100 Subject: [PATCH] Explicitly import all FunctionMixins --- tests/test_mediaplayback_subunit_base.py | 22 +++++++++++++--- ynca/subunits/__init__.py | 33 +++++++----------------- ynca/subunits/ipod.py | 21 +++++++++++++-- ynca/subunits/ipodusb.py | 21 +++++++++++++-- ynca/subunits/napster.py | 21 +++++++++++++-- ynca/subunits/pandora.py | 6 ++--- ynca/subunits/pc.py | 21 +++++++++++++-- ynca/subunits/rhap.py | 21 +++++++++++++-- ynca/subunits/server.py | 21 +++++++++++++-- ynca/subunits/sirius.py | 4 +-- ynca/subunits/spotify.py | 2 +- ynca/subunits/tun.py | 2 +- ynca/subunits/usb.py | 21 +++++++++++++-- 13 files changed, 168 insertions(+), 48 deletions(-) diff --git a/tests/test_mediaplayback_subunit_base.py b/tests/test_mediaplayback_subunit_base.py index 6c06e66..27b7000 100644 --- a/tests/test_mediaplayback_subunit_base.py +++ b/tests/test_mediaplayback_subunit_base.py @@ -1,5 +1,13 @@ from ynca import Playback, PlaybackInfo, Repeat, Shuffle -from ynca.subunits import MediaPlaybackMixins +from ynca.subunits import ( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, +) from ynca.subunit import SubunitBase SYS = "SYS" @@ -47,12 +55,20 @@ ] -class DummyMediaPlaybackSubunit(MediaPlaybackMixins, SubunitBase): +class DummyMediaPlaybackSubunit( + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + ArtistFunctionMixin, + AlbumFunctionMixin, + SongFunctionMixin, + SubunitBase, +): id = "SUBUNIT" def test_initialize(connection, update_callback): - connection.get_response_list = INITIALIZE_FULL_RESPONSES dmps = DummyMediaPlaybackSubunit(connection) diff --git a/ynca/subunits/__init__.py b/ynca/subunits/__init__.py index 36ff6f4..892549a 100644 --- a/ynca/subunits/__init__.py +++ b/ynca/subunits/__init__.py @@ -4,7 +4,6 @@ from ..function import Cmd, EnumFunctionMixin, FloatFunctionMixin, StrFunctionMixin from ..enums import Playback, PlaybackInfo, Repeat, Shuffle from ..helpers import number_to_string_with_stepsize -from ..subunit import SubunitBase class AlbumFunctionMixin: @@ -19,6 +18,15 @@ class ChNameFunctionMixin: chname = StrFunctionMixin(Cmd.GET, init="METAINFO") +class FmFreqFunctionMixin: + fmfreq = FloatFunctionMixin( + converter=FloatConverter( + to_str=lambda v: number_to_string_with_stepsize(v, 2, 0.2) + ), + ) + """Read/write FM frequency. Values will be aligned to a valid stepsize.""" + + class PlaybackFunctionMixin: def playback(self, parameter: Playback): """Change playback state""" @@ -47,26 +55,3 @@ class StationFunctionMixin: class TrackFunctionMixin: track = StrFunctionMixin(Cmd.GET, init="METAINFO") - - -# A number of subunits have the same/similar featureset -# so make a common base that only needs to be tested once -class MediaPlaybackMixins( - PlaybackFunctionMixin, - PlaybackInfoFunctionMixin, - RepeatFunctionMixin, - ShuffleFunctionMixin, - ArtistFunctionMixin, - AlbumFunctionMixin, - SongFunctionMixin, -): - pass - - -class FmFreqFunctionMixin: - fmfreq = FloatFunctionMixin( - converter=FloatConverter( - to_str=lambda v: number_to_string_with_stepsize(v, 2, 0.2) - ), - ) - """Read/write FM frequency. Values will be aligned to a valid stepsize.""" diff --git a/ynca/subunits/ipod.py b/ynca/subunits/ipod.py index e843d87..bbc4943 100644 --- a/ynca/subunits/ipod.py +++ b/ynca/subunits/ipod.py @@ -3,8 +3,25 @@ from ..constants import Subunit from ..subunit import SubunitBase -from . import MediaPlaybackMixins +from . import ( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, +) -class Ipod(MediaPlaybackMixins, SubunitBase): +class Ipod( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, + SubunitBase, +): id = Subunit.IPOD diff --git a/ynca/subunits/ipodusb.py b/ynca/subunits/ipodusb.py index 65137e9..62238f6 100644 --- a/ynca/subunits/ipodusb.py +++ b/ynca/subunits/ipodusb.py @@ -2,8 +2,25 @@ from ..constants import Subunit from ..subunit import SubunitBase -from . import MediaPlaybackMixins +from . import ( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, +) -class IpodUsb(MediaPlaybackMixins, SubunitBase): +class IpodUsb( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, + SubunitBase, +): id = Subunit.IPODUSB diff --git a/ynca/subunits/napster.py b/ynca/subunits/napster.py index 36367bf..67beec9 100644 --- a/ynca/subunits/napster.py +++ b/ynca/subunits/napster.py @@ -2,8 +2,25 @@ from ..constants import Subunit from ..subunit import SubunitBase -from . import MediaPlaybackMixins +from . import ( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, +) -class Napster(MediaPlaybackMixins, SubunitBase): +class Napster( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, + SubunitBase, +): id = Subunit.NAPSTER diff --git a/ynca/subunits/pandora.py b/ynca/subunits/pandora.py index ff7e381..fa5adf7 100644 --- a/ynca/subunits/pandora.py +++ b/ynca/subunits/pandora.py @@ -14,13 +14,13 @@ class Pandora( + AlbumFunctionMixin, + ArtistFunctionMixin, PlaybackFunctionMixin, PlaybackInfoFunctionMixin, - ArtistFunctionMixin, - AlbumFunctionMixin, SongFunctionMixin, - TrackFunctionMixin, # Pandora seems to use TRACK or SONG for title based on logs. Maybe depends on firmware version? StationFunctionMixin, + TrackFunctionMixin, # Pandora seems to use TRACK or SONG for title based on logs. Maybe depends on firmware version? SubunitBase, ): id = Subunit.PANDORA diff --git a/ynca/subunits/pc.py b/ynca/subunits/pc.py index 2fab756..1cb6698 100644 --- a/ynca/subunits/pc.py +++ b/ynca/subunits/pc.py @@ -2,8 +2,25 @@ from ..constants import Subunit from ..subunit import SubunitBase -from . import MediaPlaybackMixins +from . import ( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, +) -class Pc(MediaPlaybackMixins, SubunitBase): +class Pc( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, + SubunitBase, +): id = Subunit.PC diff --git a/ynca/subunits/rhap.py b/ynca/subunits/rhap.py index 257b6fb..fdc93f4 100644 --- a/ynca/subunits/rhap.py +++ b/ynca/subunits/rhap.py @@ -2,8 +2,25 @@ from ..constants import Subunit from ..subunit import SubunitBase -from . import MediaPlaybackMixins +from . import ( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, +) -class Rhap(MediaPlaybackMixins, SubunitBase): +class Rhap( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, + SubunitBase, +): id = Subunit.RHAP diff --git a/ynca/subunits/server.py b/ynca/subunits/server.py index d871c6f..adc603d 100644 --- a/ynca/subunits/server.py +++ b/ynca/subunits/server.py @@ -2,8 +2,25 @@ from ..constants import Subunit from ..subunit import SubunitBase -from . import MediaPlaybackMixins +from . import ( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, +) -class Server(MediaPlaybackMixins, SubunitBase): +class Server( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, + SubunitBase, +): id = Subunit.SERVER diff --git a/ynca/subunits/sirius.py b/ynca/subunits/sirius.py index 16770b6..4dd8d03 100644 --- a/ynca/subunits/sirius.py +++ b/ynca/subunits/sirius.py @@ -13,8 +13,8 @@ class Sirius( ArtistFunctionMixin, - SongFunctionMixin, ChNameFunctionMixin, + SongFunctionMixin, SubunitBase, ): id = Subunit.SIRIUS @@ -22,10 +22,10 @@ class Sirius( class SiriusIr( ArtistFunctionMixin, - SongFunctionMixin, ChNameFunctionMixin, PlaybackFunctionMixin, PlaybackInfoFunctionMixin, + SongFunctionMixin, SubunitBase, ): id = Subunit.SIRIUSIR diff --git a/ynca/subunits/spotify.py b/ynca/subunits/spotify.py index 3af8fe4..e0a493e 100644 --- a/ynca/subunits/spotify.py +++ b/ynca/subunits/spotify.py @@ -1,6 +1,7 @@ from __future__ import annotations from ..constants import Subunit +from ..subunit import SubunitBase from . import ( AlbumFunctionMixin, ArtistFunctionMixin, @@ -8,7 +9,6 @@ PlaybackInfoFunctionMixin, RepeatFunctionMixin, ShuffleFunctionMixin, - SubunitBase, TrackFunctionMixin, ) diff --git a/ynca/subunits/tun.py b/ynca/subunits/tun.py index 0dadfda..4d53806 100644 --- a/ynca/subunits/tun.py +++ b/ynca/subunits/tun.py @@ -9,7 +9,7 @@ from . import FmFreqFunctionMixin -class Tun(SubunitBase, FmFreqFunctionMixin): +class Tun(FmFreqFunctionMixin, SubunitBase): id = Subunit.TUN band = EnumFunctionMixin[BandTun](BandTun) diff --git a/ynca/subunits/usb.py b/ynca/subunits/usb.py index 3857375..606196c 100644 --- a/ynca/subunits/usb.py +++ b/ynca/subunits/usb.py @@ -2,8 +2,25 @@ from ..constants import Subunit from ..subunit import SubunitBase -from . import MediaPlaybackMixins +from . import ( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, +) -class Usb(MediaPlaybackMixins, SubunitBase): +class Usb( + AlbumFunctionMixin, + ArtistFunctionMixin, + PlaybackFunctionMixin, + PlaybackInfoFunctionMixin, + RepeatFunctionMixin, + ShuffleFunctionMixin, + SongFunctionMixin, + SubunitBase, +): id = Subunit.USB