-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayers.py
77 lines (66 loc) · 2.34 KB
/
players.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from soco import SoCo
class Players:
def __init__(self, config):
self.__config = config
self.__players = config.get_players()
self.__cursor = 0
# Initial setup of the player.
self.__update_player()
def get_player(self):
"""
Gets the currently selected player IP address.
:return: Returns the IP address of the selected player.
"""
return self.__current_player
def next_player(self):
"""
Sets the current player to the next player in the list.
:return: Returns None.
"""
if self.__cursor == len(self.__players) - 1:
self.__cursor = 0
else:
self.__cursor += 1
self.__update_player()
def previous_player(self):
"""
Sets the current player to the previous player in the list.
:return: Returns none.
"""
if self.__cursor == 0:
self.__cursor = len(self.__players) - 1
else:
self.__cursor -= 1
self.__update_player()
def volume_up(self):
"""
Raises the volume by the interval set in the configuration.
:return: Returns none.
"""
player = self.__current_player
volume_interval = self.__config.get_interval()
player.set_relative_volume(volume_interval)
print(f"Sonos {player.player_name}: Volume raised to {player.volume}%.")
def volume_down(self):
"""
Lowers the volume by the interval set in the configuration.
:return: Returns none.
"""
player = self.__current_player
volume_interval = self.__config.get_interval() - (self.__config.get_interval() * 2)
player.set_relative_volume(volume_interval)
print(f"Sonos {player.player_name}: Volume lowered to {player.volume}%.")
def volume_mute(self):
"""
Toggles muting the volume.
:return: Returns none.
"""
player = self.__current_player
if player.mute is False:
player.mute = True
print(f"Sonos {player.player_name}: Volume muted.")
else:
player.mute = False
print(f"Sonos {player.player_name}: Volume unmuted. Current volume is {player.volume}%.")
def __update_player(self):
self.__current_player = SoCo(self.__players[self.__cursor])