Skip to content

Commit

Permalink
Remove {get,set}_eq_variable() helpers, surround_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Dec 14, 2021
1 parent 709ff5e commit ed84f74
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 53 deletions.
96 changes: 59 additions & 37 deletions soco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ class SoCo(_SocoSingletonBase):
balance
night_mode
dialog_mode
surround_mode
surround_mode_music_playback
surround_music_playback
surround_volume_tv
surround_volume_music
soundbar_audio_input_format
Expand Down Expand Up @@ -1138,7 +1137,10 @@ def night_mode(self):
if not self.is_soundbar:
return None

return self.renderingControl.get_eq_variable("NightMode")
response = self.renderingControl.GetEQ(
[("InstanceID", 0), ("EQType", "NightMode")]
)
return bool(int(response["CurrentValue"]))

@night_mode.setter
@only_on_soundbars
Expand All @@ -1150,7 +1152,13 @@ def night_mode(self, night_mode):
:raises NotSupportedException: If the device does not support
night mode.
"""
self.renderingControl.set_eq_variable("NightMode", int(night_mode))
self.renderingControl.SetEQ(
[
("InstanceID", 0),
("EQType", "NightMode"),
("DesiredValue", int(night_mode)),
]
)

@property
def dialog_mode(self):
Expand All @@ -1161,7 +1169,10 @@ def dialog_mode(self):
if not self.is_soundbar:
return None

return bool(self.renderingControl.get_eq_variable("DialogLevel"))
response = self.renderingControl.GetEQ(
[("InstanceID", 0), ("EQType", "DialogLevel")]
)
return bool(int(response["CurrentValue"]))

@dialog_mode.setter
@only_on_soundbars
Expand All @@ -1173,32 +1184,16 @@ def dialog_mode(self, dialog_mode):
:raises NotSupportedException: If the device does not support
dialog mode.
"""
self.renderingControl.set_eq_variable("DialogLevel", int(dialog_mode))

@property
def surround_mode(self) -> Optional[bool]:
"""bool: The speaker's surround mode.
True if on, False if off, None if not supported.
"""
if not self.is_soundbar:
return None

return bool(self.renderingControl.get_eq_variable("SurroundEnable"))

@surround_mode.setter
@only_on_soundbars
def surround_mode(self, surround_mode: bool):
"""Switch on/off the speaker's surround mode.
:param surround_mode: Enable or disable surround mode
:type surround_mode: bool
:raises NotSupportedException: If the device does not support
surround mode."""
self.renderingControl.set_eq_variable("SurroundEnable", int(surround_mode))
self.renderingControl.SetEQ(
[
("InstanceID", 0),
("EQType", "DialogLevel"),
("DesiredValue", int(dialog_mode)),
]
)

@property
def surround_mode_music_playback(self) -> Optional[int]:
def surround_music_playback(self) -> Optional[int]:
"""Return the music playback mode (ambient, full volume) for surrounds.
Note: this does not apply to the TV mode.
Expand All @@ -1211,11 +1206,14 @@ def surround_mode_music_playback(self) -> Optional[int]:
if not self.is_soundbar:
return None

return self.renderingControl.get_eq_variable("SurroundMode")
response = self.renderingControl.GetEQ(
[("InstanceID", 0), ("EQType", "SurroundMode")]
)
return int(response["CurrentValue"])

@surround_mode_music_playback.setter
@surround_music_playback.setter
@only_on_soundbars
def surround_mode_music_playback(self, value: int):
def surround_music_playback(self, value: int):
"""Set the music playback mode (ambient, full volume) for surrounds.
Note: this does not apply to the TV mode.
Expand All @@ -1225,15 +1223,24 @@ def surround_mode_music_playback(self, value: int):
0: ambient
1: full
"""
return self.renderingControl.set_eq_variable("SurroundMode", value)
self.renderingControl.SetEQ(
[
("InstanceID", 0),
("EQType", "SurroundMode"),
("DesiredValue", value),
]
)

@property
def surround_volume_tv(self) -> Optional[int]:
"""Return the relative volume [-15,15] for surround speakers in the TV mode."""
if not self.is_soundbar:
return None

return self.renderingControl.get_eq_variable("SurroundLevel")
response = self.renderingControl.GetEQ(
[("InstanceID", 0), ("EQType", "SurroundLevel")]
)
return int(response["CurrentValue"])

@surround_volume_tv.setter
@only_on_soundbars
Expand All @@ -1245,7 +1252,13 @@ def surround_volume_tv(self, relative_volume: int):
if not -15 <= relative_volume <= 15:
raise ValueError("Value must be [-15, 15]")

self.renderingControl.set_eq_variable("SurroundLevel", relative_volume)
self.renderingControl.SetEQ(
[
("InstanceID", 0),
("EQType", "SurroundLevel"),
("DesiredValue", relative_volume),
]
)

@property
def surround_volume_music(self) -> Optional[int]:
Expand All @@ -1256,7 +1269,10 @@ def surround_volume_music(self) -> Optional[int]:
if not self.is_soundbar:
return None

return self.renderingControl.get_eq_variable("MusicSurroundLevel")
response = self.renderingControl.GetEQ(
[("InstanceID", 0), ("EQType", "MusicSurroundLevel")]
)
return int(response["CurrentValue"])

@surround_volume_music.setter
@only_on_soundbars
Expand All @@ -1265,7 +1281,13 @@ def surround_volume_music(self, relative_volume: int):
if not -15 <= relative_volume <= 15:
raise ValueError("Value must be [-15, 15]")

self.renderingControl.set_eq_variable("MusicSurroundLevel", relative_volume)
self.renderingControl.SetEQ(
[
("InstanceID", 0),
("EQType", "MusicSurroundLevel"),
("DesiredValue", relative_volume),
]
)

@property
def trueplay(self):
Expand Down
16 changes: 0 additions & 16 deletions soco/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,22 +866,6 @@ def __init__(self, soco):
self.event_subscription_url = "/MediaRenderer/RenderingControl/Event"
self.DEFAULT_ARGS.update({"InstanceID": 0})

def get_eq_variable(self, variable: str) -> int:
"""Return the EQ value for given variable as an integer."""
response = self.GetEQ([("InstanceID", 0), ("EQType", variable)])

return int(response["CurrentValue"])

def set_eq_variable(self, variable: str, value: int):
"""Set the EQ variable to given (integer) value."""
return self.SetEQ(
[
("InstanceID", 0),
("EQType", variable),
("DesiredValue", value),
]
)


class MR_ConnectionManager(Service): # pylint: disable=invalid-name
"""UPnP standard connection manager service for the media renderer."""
Expand Down

0 comments on commit ed84f74

Please sign in to comment.