From b883014ed4d07f7e0d86a36b81a56766075a1952 Mon Sep 17 00:00:00 2001 From: jjlawren Date: Fri, 3 Dec 2021 09:05:40 -0600 Subject: [PATCH] Add Sonos subwoofer and surround on/off controls (#60918) --- homeassistant/components/sonos/speaker.py | 2 ++ homeassistant/components/sonos/switch.py | 8 ++++++++ tests/components/sonos/conftest.py | 2 ++ tests/components/sonos/test_switch.py | 12 +++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/sonos/speaker.py b/homeassistant/components/sonos/speaker.py index 4cec0fbb6ab..4838da69c50 100644 --- a/homeassistant/components/sonos/speaker.py +++ b/homeassistant/components/sonos/speaker.py @@ -196,6 +196,8 @@ class SonosSpeaker: self.cross_fade: bool | None = None self.bass: int | None = None self.treble: int | None = None + self.sub_enabled: bool | None = None + self.surround_enabled: bool | None = None # Misc features self.buttons_enabled: bool | None = None diff --git a/homeassistant/components/sonos/switch.py b/homeassistant/components/sonos/switch.py index 78469dc8bbc..f6fe81953f5 100644 --- a/homeassistant/components/sonos/switch.py +++ b/homeassistant/components/sonos/switch.py @@ -38,6 +38,8 @@ ATTR_CROSSFADE = "cross_fade" ATTR_NIGHT_SOUND = "night_mode" ATTR_SPEECH_ENHANCEMENT = "dialog_mode" ATTR_STATUS_LIGHT = "status_light" +ATTR_SUB_ENABLED = "sub_enabled" +ATTR_SURROUND_ENABLED = "surround_enabled" ATTR_TOUCH_CONTROLS = "buttons_enabled" ALL_FEATURES = ( @@ -45,6 +47,8 @@ ALL_FEATURES = ( ATTR_CROSSFADE, ATTR_NIGHT_SOUND, ATTR_SPEECH_ENHANCEMENT, + ATTR_SUB_ENABLED, + ATTR_SURROUND_ENABLED, ATTR_STATUS_LIGHT, ) @@ -60,6 +64,8 @@ FRIENDLY_NAMES = { ATTR_NIGHT_SOUND: "Night Sound", ATTR_SPEECH_ENHANCEMENT: "Speech Enhancement", ATTR_STATUS_LIGHT: "Status Light", + ATTR_SUB_ENABLED: "Subwoofer Enabled", + ATTR_SURROUND_ENABLED: "Surround Enabled", ATTR_TOUCH_CONTROLS: "Touch Controls", } @@ -68,6 +74,8 @@ FEATURE_ICONS = { ATTR_SPEECH_ENHANCEMENT: "mdi:ear-hearing", ATTR_CROSSFADE: "mdi:swap-horizontal", ATTR_STATUS_LIGHT: "mdi:led-on", + ATTR_SUB_ENABLED: "mdi:dog", + ATTR_SURROUND_ENABLED: "mdi:surround-sound", ATTR_TOUCH_CONTROLS: "mdi:gesture-tap", } diff --git a/tests/components/sonos/conftest.py b/tests/components/sonos/conftest.py index 8a55d285a41..a17f07c3c35 100644 --- a/tests/components/sonos/conftest.py +++ b/tests/components/sonos/conftest.py @@ -72,6 +72,8 @@ def soco_fixture(music_library, speaker_info, battery_info, alarm_clock): mock_soco.volume = 19 mock_soco.bass = 1 mock_soco.treble = -1 + mock_soco.sub_enabled = False + mock_soco.surround_enabled = True mock_soco.get_battery_info.return_value = battery_info mock_soco.all_zones = [mock_soco] yield mock_soco diff --git a/tests/components/sonos/test_switch.py b/tests/components/sonos/test_switch.py index c2f997dbcb6..9c25e2b8cc7 100644 --- a/tests/components/sonos/test_switch.py +++ b/tests/components/sonos/test_switch.py @@ -14,7 +14,7 @@ from homeassistant.components.sonos.switch import ( ATTR_VOLUME, ) from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY -from homeassistant.const import ATTR_TIME, STATE_ON +from homeassistant.const import ATTR_TIME, STATE_OFF, STATE_ON from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry from homeassistant.setup import async_setup_component from homeassistant.util import dt @@ -42,6 +42,8 @@ async def test_entity_registry(hass, config_entry, config): assert "switch.sonos_zone_a_status_light" in entity_registry.entities assert "switch.sonos_zone_a_night_sound" in entity_registry.entities assert "switch.sonos_zone_a_speech_enhancement" in entity_registry.entities + assert "switch.sonos_zone_a_subwoofer_enabled" in entity_registry.entities + assert "switch.sonos_zone_a_surround_enabled" in entity_registry.entities assert "switch.sonos_zone_a_touch_controls" in entity_registry.entities @@ -83,6 +85,14 @@ async def test_switch_attributes(hass, config_entry, config, soco): touch_controls = entity_registry.entities["switch.sonos_zone_a_touch_controls"] assert hass.states.get(touch_controls.entity_id) is None + sub_switch = entity_registry.entities["switch.sonos_zone_a_subwoofer_enabled"] + sub_switch_state = hass.states.get(sub_switch.entity_id) + assert sub_switch_state.state == STATE_OFF + + surround_switch = entity_registry.entities["switch.sonos_zone_a_surround_enabled"] + surround_switch_state = hass.states.get(surround_switch.entity_id) + assert surround_switch_state.state == STATE_ON + # Enable disabled switches for entity in (status_light, touch_controls): entity_registry.async_update_entity(