Skip to content

Commit 63ea06b

Browse files
committed
Add Deezer (copy of Tidal)
1 parent ce4b48a commit 63ea06b

6 files changed

Lines changed: 125 additions & 0 deletions

File tree

src/ynca/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from .subunits.airplay import Airplay
5151
from .subunits.bt import Bt
5252
from .subunits.dab import Dab
53+
from .subunits.deezer import Deezer
5354
from .subunits.ipod import Ipod
5455
from .subunits.ipodusb import IpodUsb
5556
from .subunits.napster import Napster
@@ -76,6 +77,7 @@
7677
"Bt",
7778
"Dab",
7879
"DabPreset",
80+
"Deezer",
7981
"DirMode",
8082
"Enhancer",
8183
"FmPreset",

src/ynca/api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .subunits.airplay import Airplay
1818
from .subunits.bt import Bt
1919
from .subunits.dab import Dab
20+
from .subunits.deezer import Deezer
2021
from .subunits.ipod import Ipod
2122
from .subunits.ipodusb import IpodUsb
2223
from .subunits.napster import Napster
@@ -268,6 +269,10 @@ def bt(self) -> Bt | None:
268269
def dab(self) -> Dab | None:
269270
return cast(Dab, self._subunits.get(Subunit.DAB, None))
270271

272+
@property
273+
def deezer(self) -> Deezer | None:
274+
return cast(Deezer, self._subunits.get(Subunit.DEEZER, None))
275+
271276
@property
272277
def ipod(self) -> Ipod | None:
273278
return cast(Ipod, self._subunits.get(Subunit.IPOD, None))

src/ynca/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Subunit(StrEnum):
2121
AIRPLAY = "AIRPLAY"
2222
BT = "BT"
2323
DAB = "DAB"
24+
DEEZER = "DEEZER"
2425
IPOD = "IPOD"
2526
IPODUSB = "IPODUSB"
2627
NAPSTER = "NAPSTER"

src/ynca/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class Input(StrEnum):
217217
# Inputs provided by subunits
218218
AIRPLAY = "AirPlay"
219219
BLUETOOTH = "Bluetooth"
220+
DEEZER = "Deezer"
220221
IPOD = "iPod"
221222
IPOD_USB = "iPod (USB)"
222223
NAPSTER = "Napster"

src/ynca/subunits/deezer.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from __future__ import annotations
2+
3+
from ..constants import Subunit
4+
from ..subunit import SubunitBase
5+
from . import (
6+
AlbumFunctionMixin,
7+
ArtistFunctionMixin,
8+
ElapsedTimeFunctionMixin,
9+
PlaybackFunctionMixin,
10+
PlaybackInfoFunctionMixin,
11+
RepeatFunctionMixin,
12+
ShuffleFunctionMixin,
13+
TotalTimeFunctionMixin,
14+
TrackFunctionMixin,
15+
)
16+
17+
18+
class Deezer(
19+
AlbumFunctionMixin,
20+
ArtistFunctionMixin,
21+
ElapsedTimeFunctionMixin,
22+
PlaybackFunctionMixin,
23+
PlaybackInfoFunctionMixin,
24+
RepeatFunctionMixin,
25+
ShuffleFunctionMixin,
26+
TotalTimeFunctionMixin,
27+
TrackFunctionMixin,
28+
SubunitBase,
29+
):
30+
id = Subunit.DEEZER

tests/test_deezer.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
from collections.abc import Callable
2+
from datetime import timedelta
3+
from typing import Any
4+
5+
from tests.mock_yncaconnection import YncaConnectionMock
6+
from ynca import Playback, PlaybackInfo, Repeat, Shuffle
7+
from ynca.subunits.deezer import Deezer
8+
9+
SYS = "SYS"
10+
SUBUNIT = "DEEZER"
11+
12+
INITIALIZE_FULL_RESPONSES = [
13+
(
14+
(SUBUNIT, "METAINFO"),
15+
[
16+
(SUBUNIT, "ALBUM", "Album"),
17+
(SUBUNIT, "ARTIST", "Artist"),
18+
(SUBUNIT, "TRACK", "Track"),
19+
],
20+
),
21+
(
22+
(SUBUNIT, "AVAIL"),
23+
[
24+
(SUBUNIT, "AVAIL", "Ready"),
25+
],
26+
),
27+
(
28+
(SUBUNIT, "ELAPSEDTIME"),
29+
[
30+
(SUBUNIT, "ELAPSEDTIME", ""),
31+
],
32+
),
33+
(
34+
(SUBUNIT, "PLAYBACKINFO"),
35+
[
36+
(SUBUNIT, "PLAYBACKINFO", "Pause"),
37+
],
38+
),
39+
(
40+
(SUBUNIT, "REPEAT"),
41+
[
42+
(SUBUNIT, "REPEAT", "Single"),
43+
],
44+
),
45+
(
46+
(SUBUNIT, "SHUFFLE"),
47+
[
48+
(SUBUNIT, "SHUFFLE", "On"),
49+
],
50+
),
51+
(
52+
(SUBUNIT, "TOTALTIME"),
53+
[
54+
(SUBUNIT, "TOTALTIME", "1:23"),
55+
],
56+
),
57+
(
58+
(SYS, "VERSION"),
59+
[
60+
(SYS, "VERSION", "Version"),
61+
],
62+
),
63+
]
64+
65+
66+
def test_initialize(
67+
connection: YncaConnectionMock, update_callback: Callable[[str, Any], None]
68+
) -> None:
69+
connection.get_response_list = INITIALIZE_FULL_RESPONSES
70+
71+
tidal = Deezer(connection)
72+
tidal.register_update_callback(update_callback)
73+
74+
tidal.initialize()
75+
76+
assert tidal.album == "Album"
77+
assert tidal.artist == "Artist"
78+
assert tidal.track == "Track"
79+
assert tidal.playbackinfo is PlaybackInfo.PAUSE
80+
assert tidal.repeat == Repeat.SINGLE
81+
assert tidal.shuffle == Shuffle.ON
82+
assert tidal.elapsedtime is None
83+
assert tidal.totaltime == timedelta(minutes=1, seconds=23)
84+
85+
tidal.playback(Playback.PLAY)
86+
connection.put.assert_called_with(SUBUNIT, "PLAYBACK", "Play")

0 commit comments

Comments
 (0)