Skip to content

Commit

Permalink
add sleep to status
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisChrist committed Apr 14, 2024
1 parent 3602d7e commit 24b2705
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/pyblu/_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class Status:
total_seconds: float
"""Total track length in seconds"""

sleep: int
"""Sleep timer in minutes. 0 means the sleep timer is off."""


@dataclass
class PairedPlayer:
Expand Down
1 change: 1 addition & 0 deletions src/pyblu/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def parse_status(response_dict: dict[str, Any]) -> Status:
mute_volume_db=chained_get(response_dict, "status", "muteDb", _map=int),
seconds=chained_get(response_dict, "status", "secs", _map=int),
total_seconds=chained_get(response_dict, "status", "totlen", _map=float),
sleep=chained_get(response_dict, "status", "sleep", _map=int, default=0),
)

return status
Expand Down
16 changes: 15 additions & 1 deletion tests/test_parse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import xmltodict

from pyblu import PairedPlayer
from pyblu._parse import parse_slave_list
from pyblu._parse import parse_slave_list, parse_status


def test_sync_status_no_slave():
Expand Down Expand Up @@ -41,3 +43,15 @@ def test_parse_slave_list_multiple_elements():
PairedPlayer(ip="1.1.1.1", port=11000),
PairedPlayer(ip="2.2.2.2", port=11000),
]


def test_parse_status_default_sleep():
data = """<status etag="4e266c9fbfba6d13d1a4d6ff4bd2e1e6">
<sleep/>
</status>"""

response_dict = xmltodict.parse(data)

status = parse_status(response_dict)

assert status.sleep == 0
4 changes: 4 additions & 0 deletions tests/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ async def test_status():
<secs>10</secs>
<totlen>100</totlen>
<sleep>15</sleep>
</status>
""",
)
Expand All @@ -116,6 +118,8 @@ async def test_status():
assert status.seconds == 10
assert status.total_seconds == 100.0

assert status.sleep == 15


async def test_sync_status():
with aioresponses() as mocked:
Expand Down

0 comments on commit 24b2705

Please sign in to comment.