Skip to content

Commit

Permalink
Explicitly import all FunctionMixins
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdwetering committed Jan 27, 2024
1 parent 256e429 commit 4386ab7
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 48 deletions.
22 changes: 19 additions & 3 deletions tests/test_mediaplayback_subunit_base.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 9 additions & 24 deletions ynca/subunits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"""
Expand Down Expand Up @@ -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."""
21 changes: 19 additions & 2 deletions ynca/subunits/ipod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 19 additions & 2 deletions ynca/subunits/ipodusb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 19 additions & 2 deletions ynca/subunits/napster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions ynca/subunits/pandora.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 19 additions & 2 deletions ynca/subunits/pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 19 additions & 2 deletions ynca/subunits/rhap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 19 additions & 2 deletions ynca/subunits/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions ynca/subunits/sirius.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@

class Sirius(
ArtistFunctionMixin,
SongFunctionMixin,
ChNameFunctionMixin,
SongFunctionMixin,
SubunitBase,
):
id = Subunit.SIRIUS


class SiriusIr(
ArtistFunctionMixin,
SongFunctionMixin,
ChNameFunctionMixin,
PlaybackFunctionMixin,
PlaybackInfoFunctionMixin,
SongFunctionMixin,
SubunitBase,
):
id = Subunit.SIRIUSIR
Expand Down
2 changes: 1 addition & 1 deletion ynca/subunits/spotify.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

from ..constants import Subunit
from ..subunit import SubunitBase
from . import (
AlbumFunctionMixin,
ArtistFunctionMixin,
PlaybackFunctionMixin,
PlaybackInfoFunctionMixin,
RepeatFunctionMixin,
ShuffleFunctionMixin,
SubunitBase,
TrackFunctionMixin,
)

Expand Down
2 changes: 1 addition & 1 deletion ynca/subunits/tun.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import FmFreqFunctionMixin


class Tun(SubunitBase, FmFreqFunctionMixin):
class Tun(FmFreqFunctionMixin, SubunitBase):
id = Subunit.TUN

band = EnumFunctionMixin[BandTun](BandTun)
Expand Down
21 changes: 19 additions & 2 deletions ynca/subunits/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4386ab7

Please sign in to comment.