Add Sound Mode selection in soundpal components (#106589)

This commit is contained in:
BestPig
2024-04-16 17:45:48 +02:00
committed by GitHub
parent 135fe26704
commit 586d27320e
3 changed files with 109 additions and 1 deletions
+18
View File
@@ -85,6 +85,24 @@ def _create_mocked_device(throw_exception=False, wired_mac=MAC, wireless_mac=Non
input2.active = True
type(mocked_device).get_inputs = AsyncMock(return_value=[input1, input2])
sound_mode1 = MagicMock()
sound_mode1.title = "Sound Mode 1"
sound_mode1.value = "sound_mode1"
sound_mode1.isAvailable = True
sound_mode2 = MagicMock()
sound_mode2.title = "Sound Mode 2"
sound_mode2.value = "sound_mode2"
sound_mode2.isAvailable = True
sound_mode3 = MagicMock()
sound_mode3.title = "Sound Mode 3"
sound_mode3.value = "sound_mode3"
sound_mode3.isAvailable = False
soundField = MagicMock()
soundField.currentValue = "sound_mode2"
soundField.candidate = [sound_mode1, sound_mode2, sound_mode3]
type(mocked_device).get_sound_settings = AsyncMock(return_value=[soundField])
type(mocked_device).set_power = AsyncMock()
type(mocked_device).set_sound_settings = AsyncMock()
type(mocked_device).listen_notifications = AsyncMock()
+21 -1
View File
@@ -12,6 +12,7 @@ from songpal import (
SongpalException,
VolumeChange,
)
from songpal.notification import SettingChange
from homeassistant.components import media_player, songpal
from homeassistant.components.media_player import MediaPlayerEntityFeature
@@ -47,6 +48,7 @@ SUPPORT_SONGPAL = (
| MediaPlayerEntityFeature.VOLUME_STEP
| MediaPlayerEntityFeature.VOLUME_MUTE
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.SELECT_SOUND_MODE
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
)
@@ -138,6 +140,8 @@ async def test_state(hass: HomeAssistant) -> None:
assert attributes["is_volume_muted"] is False
assert attributes["source_list"] == ["title1", "title2"]
assert attributes["source"] == "title2"
assert attributes["sound_mode_list"] == ["Sound Mode 1", "Sound Mode 2"]
assert attributes["sound_mode"] == "Sound Mode 2"
assert attributes["supported_features"] == SUPPORT_SONGPAL
device_registry = dr.async_get(hass)
@@ -171,6 +175,8 @@ async def test_state_wireless(hass: HomeAssistant) -> None:
assert attributes["is_volume_muted"] is False
assert attributes["source_list"] == ["title1", "title2"]
assert attributes["source"] == "title2"
assert attributes["sound_mode_list"] == ["Sound Mode 1", "Sound Mode 2"]
assert attributes["sound_mode"] == "Sound Mode 2"
assert attributes["supported_features"] == SUPPORT_SONGPAL
device_registry = dr.async_get(hass)
@@ -206,6 +212,8 @@ async def test_state_both(hass: HomeAssistant) -> None:
assert attributes["is_volume_muted"] is False
assert attributes["source_list"] == ["title1", "title2"]
assert attributes["source"] == "title2"
assert attributes["sound_mode_list"] == ["Sound Mode 1", "Sound Mode 2"]
assert attributes["sound_mode"] == "Sound Mode 2"
assert attributes["supported_features"] == SUPPORT_SONGPAL
device_registry = dr.async_get(hass)
@@ -303,6 +311,9 @@ async def test_services(hass: HomeAssistant) -> None:
mocked_device2.set_sound_settings.assert_called_once_with("name", "value")
mocked_device3.set_sound_settings.assert_called_once_with("name", "value")
await _call(hass, media_player.SERVICE_SELECT_SOUND_MODE, sound_mode="Sound Mode 1")
mocked_device.set_sound_settings.assert_called_with("soundField", "sound_mode1")
async def test_websocket_events(hass: HomeAssistant) -> None:
"""Test websocket events."""
@@ -315,7 +326,7 @@ async def test_websocket_events(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
mocked_device.listen_notifications.assert_called_once()
assert mocked_device.on_notification.call_count == 4
assert mocked_device.on_notification.call_count == 5
notification_callbacks = mocked_device.notification_callbacks
@@ -336,6 +347,15 @@ async def test_websocket_events(hass: HomeAssistant) -> None:
await notification_callbacks[ContentChange](content_change)
assert _get_attributes(hass)["source"] == "title1"
sound_mode_change = MagicMock()
sound_mode_change.target = "soundField"
sound_mode_change.currentValue = "sound_mode1"
await notification_callbacks[SettingChange](sound_mode_change)
assert _get_attributes(hass)["sound_mode"] == "Sound Mode 1"
sound_mode_change.currentValue = "sound_mode2"
await notification_callbacks[SettingChange](sound_mode_change)
assert _get_attributes(hass)["sound_mode"] == "Sound Mode 2"
power_change = MagicMock()
power_change.status = False
await notification_callbacks[PowerChange](power_change)