Skip to content

Commit 3142825

Browse files
authored
Merge pull request #5 from MusicBoxRaspberryPi/develop
Remove Index Change If Devices Refreshed
2 parents 52a7697 + 93030bf commit 3142825

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

app/spotify/router.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ def get_current_device(
3737
def next_device(
3838
spotify_service: SpotifyService = Depends(Provide[Container.spotify_service])
3939
) -> CurrentDevice | dict:
40-
spotify_service.refresh_devices()
41-
spotify_service.next_device()
40+
updated = spotify_service.refresh_devices()
41+
42+
if not updated:
43+
spotify_service.next_device()
44+
4245
current_device = spotify_service.get_current_device()
4346

4447
if current_device is None:
@@ -56,8 +59,11 @@ def next_device(
5659
def previous_device(
5760
spotify_service: SpotifyService = Depends(Provide[Container.spotify_service])
5861
) -> CurrentDevice | dict:
59-
spotify_service.refresh_devices()
60-
spotify_service.previous_device()
62+
updated = spotify_service.refresh_devices()
63+
64+
if not updated:
65+
spotify_service.previous_device()
66+
6167
current_device = spotify_service.get_current_device()
6268

6369
if current_device is None:

app/spotify/service.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,20 @@ def play(self, track: Track) -> None:
4343
elif "Invalid track uri" in e.msg:
4444
raise TrackNotFoundError(e.msg)
4545

46-
def refresh_devices(self) -> list[Device]:
46+
def refresh_devices(self) -> bool:
47+
"""
48+
Refreshes the devices from the API and returns whether the devices have changed
49+
50+
:return: Whether the devices have changed
51+
"""
4752
devices_from_api = self.__get_devices_from_api()
4853

4954
if devices_from_api != self.__devices:
5055
self.__devices = devices_from_api
5156
self.__current_device_index = 0
57+
return True
5258

53-
return self.__devices
59+
return False
5460

5561
def next_device(self) -> Device | None:
5662
if len(self.__devices) == 0:

0 commit comments

Comments
 (0)