Skip to content

Commit

Permalink
Add playback state
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek committed Nov 29, 2023
1 parent fba9521 commit c39303c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
8 changes: 3 additions & 5 deletions src/spotifyaio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
SpotifyConnectionError,
SpotifyError,
)
from .models import (
Device, PlaybackState,
)
from .models import Device, PlaybackState
from .spotify import SpotifyClient

__all__ = [
Expand All @@ -15,5 +13,5 @@
"SpotifyConnectionError",
"SpotifyAuthenticationFailedError",
"SpotifyClient",
"PlaybackState"
]
"PlaybackState",
]
10 changes: 7 additions & 3 deletions src/spotifyaio/models.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from dataclasses import dataclass
"""Models for Spotify."""
from dataclasses import dataclass, field

from mashumaro import field_options
from mashumaro.mixins.orjson import DataClassORJSONMixin


@dataclass
class Device(DataClassORJSONMixin):
"""Device model."""

id: str
device_id: str = field(metadata=field_options(alias="id"))
is_active: bool
is_private_session: bool
name: str
supports_volume: bool
type: str
device_type: str = field(metadata=field_options(alias="type"))
volume_percent: int


@dataclass
class PlaybackState(DataClassORJSONMixin):
"""Playback state model."""

device: Device
5 changes: 4 additions & 1 deletion src/spotifyaio/spotify.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Spotify client for handling connections with Spotify."""
from __future__ import annotations

import asyncio
from dataclasses import dataclass
from importlib import metadata
from typing import Callable, Awaitable, Any, Self
from typing import Any, Awaitable, Callable, Self

from aiohttp import ClientSession
from aiohttp.hdrs import METH_GET
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/test_playback.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# name: test_get_devices
dict({
'device': dict({
'id': '21dac6b0e0a1f181870fdc9749b2656466557687',
'device_id': '21dac6b0e0a1f181870fdc9749b2656466557687',
'device_type': 'Computer',
'is_active': True,
'is_private_session': False,
'name': 'DESKTOP-BKC5SIK',
'supports_volume': True,
'type': 'Computer',
'volume_percent': 69,
}),
})
Expand Down
9 changes: 1 addition & 8 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@
from __future__ import annotations

import asyncio
import json

import aiohttp
from aiohttp.hdrs import METH_GET
from aiohttp.web_request import BaseRequest
from aresponses import Response, ResponsesMockServer
import pytest

from spotifyaio import (
SpotifyAuthenticationFailedError,
SpotifyClient,
SpotifyConnectionError,
SpotifyError,
)
from spotifyaio import SpotifyClient, SpotifyConnectionError, SpotifyError

from . import load_fixture
from .const import SPOTIFY_URL
Expand Down Expand Up @@ -100,4 +94,3 @@ async def response_handler(_: BaseRequest) -> Response:
with pytest.raises(SpotifyConnectionError):
assert await spotify.get_playback()
await spotify.close()

3 changes: 1 addition & 2 deletions tests/test_playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import aiohttp
from aiohttp.hdrs import METH_GET
from aresponses import ResponsesMockServer
import pytest

from spotifyaio.spotify import SpotifyClient
from syrupy import SnapshotAssertion

from spotifyaio.spotify import SpotifyClient
from . import load_fixture
from .const import SPOTIFY_URL

Expand Down

0 comments on commit c39303c

Please sign in to comment.