Add support for Sonos subwoofer gain controls (#68334)

pull/68346/head
jjlawren 2022-03-18 12:12:10 -05:00 committed by GitHub
parent 7174e7897c
commit dbb79e2937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 3 deletions

View File

@ -19,6 +19,7 @@ LEVEL_TYPES = {
"audio_delay": (0, 5),
"bass": (-10, 10),
"treble": (-10, 10),
"sub_gain": (-15, 15),
}
_LOGGER = logging.getLogger(__name__)

View File

@ -150,6 +150,7 @@ class SonosSpeaker:
self.dialog_level: bool | None = None
self.night_mode: bool | None = None
self.sub_enabled: bool | None = None
self.sub_gain: int | None = None
self.surround_enabled: bool | None = None
# Misc features
@ -490,7 +491,7 @@ class SonosSpeaker:
if bool_var in variables:
setattr(self, bool_var, variables[bool_var] == "1")
for int_var in ("audio_delay", "bass", "treble"):
for int_var in ("audio_delay", "bass", "treble", "sub_gain"):
if int_var in variables:
setattr(self, int_var, variables[int_var])

View File

@ -114,6 +114,7 @@ def soco_fixture(
mock_soco.treble = -1
mock_soco.mic_enabled = False
mock_soco.sub_enabled = False
mock_soco.sub_gain = 5
mock_soco.surround_enabled = True
mock_soco.soundbar_audio_input_format = "Dolby 5.1"
mock_soco.get_battery_info.return_value = battery_info

View File

@ -6,8 +6,8 @@ from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.helpers import entity_registry as ent_reg
async def test_audio_input_sensor(hass, async_autosetup_sonos, soco):
"""Test audio input sensor."""
async def test_number_entities(hass, async_autosetup_sonos, soco):
"""Test number entities."""
entity_registry = ent_reg.async_get(hass)
bass_number = entity_registry.entities["number.zone_a_bass"]
@ -30,3 +30,16 @@ async def test_audio_input_sensor(hass, async_autosetup_sonos, soco):
blocking=True,
)
assert mock_audio_delay.called_with(3)
sub_gain_number = entity_registry.entities["number.zone_a_sub_gain"]
sub_gain_state = hass.states.get(sub_gain_number.entity_id)
assert sub_gain_state.state == "5"
with patch("soco.SoCo.sub_gain") as mock_sub_gain:
await hass.services.async_call(
NUMBER_DOMAIN,
SERVICE_SET_VALUE,
{ATTR_ENTITY_ID: sub_gain_number.entity_id, "value": -8},
blocking=True,
)
assert mock_sub_gain.called_with(-8)