mirror of
https://github.com/home-assistant/core.git
synced 2026-09-12 11:38:47 +01:00
Add equalizer switch for Cambridge Audio devices (#162956)
This commit is contained in:
@@ -29,6 +29,12 @@
|
||||
"early_update": {
|
||||
"default": "mdi:update"
|
||||
},
|
||||
"equalizer": {
|
||||
"default": "mdi:equalizer",
|
||||
"state": {
|
||||
"off": "mdi:equalizer-outline"
|
||||
}
|
||||
},
|
||||
"pre_amp": {
|
||||
"default": "mdi:volume-high",
|
||||
"state": {
|
||||
|
||||
@@ -65,6 +65,9 @@
|
||||
"early_update": {
|
||||
"name": "Early update"
|
||||
},
|
||||
"equalizer": {
|
||||
"name": "Equalizer"
|
||||
},
|
||||
"pre_amp": {
|
||||
"name": "Pre-Amp"
|
||||
},
|
||||
|
||||
@@ -33,6 +33,13 @@ def room_correction_enabled(client: StreamMagicClient) -> bool:
|
||||
return client.audio.tilt_eq.enabled
|
||||
|
||||
|
||||
def equalizer_enabled(client: StreamMagicClient) -> bool:
|
||||
"""Check if equalizer is enabled."""
|
||||
if TYPE_CHECKING:
|
||||
assert client.audio.user_eq is not None
|
||||
return client.audio.user_eq.enabled
|
||||
|
||||
|
||||
CONTROL_ENTITIES: tuple[CambridgeAudioSwitchEntityDescription, ...] = (
|
||||
CambridgeAudioSwitchEntityDescription(
|
||||
key="pre_amp",
|
||||
@@ -56,6 +63,14 @@ CONTROL_ENTITIES: tuple[CambridgeAudioSwitchEntityDescription, ...] = (
|
||||
value_fn=room_correction_enabled,
|
||||
set_value_fn=lambda client, value: client.set_room_correction_mode(value),
|
||||
),
|
||||
CambridgeAudioSwitchEntityDescription(
|
||||
key="equalizer",
|
||||
translation_key="equalizer",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
load_fn=lambda client: client.audio.user_eq is not None,
|
||||
value_fn=equalizer_enabled,
|
||||
set_value_fn=lambda client, value: client.set_equalizer_mode(value),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -2,5 +2,59 @@
|
||||
"tilt_eq": {
|
||||
"enabled": true,
|
||||
"intensity": 0
|
||||
},
|
||||
"user_eq": {
|
||||
"enabled": true,
|
||||
"bands": [
|
||||
{
|
||||
"index": 0,
|
||||
"filter": "LOWSHELF",
|
||||
"freq": 80,
|
||||
"gain": 0.0,
|
||||
"q": 0.8
|
||||
},
|
||||
{
|
||||
"index": 1,
|
||||
"filter": "PEAKING",
|
||||
"freq": 120,
|
||||
"gain": 0.0,
|
||||
"q": 1.24
|
||||
},
|
||||
{
|
||||
"index": 2,
|
||||
"filter": "PEAKING",
|
||||
"freq": 315,
|
||||
"gain": 0.0,
|
||||
"q": 1.24
|
||||
},
|
||||
{
|
||||
"index": 3,
|
||||
"filter": "PEAKING",
|
||||
"freq": 800,
|
||||
"gain": 0.0,
|
||||
"q": 1.24
|
||||
},
|
||||
{
|
||||
"index": 4,
|
||||
"filter": "PEAKING",
|
||||
"freq": 2000,
|
||||
"gain": 0.0,
|
||||
"q": 1.24
|
||||
},
|
||||
{
|
||||
"index": 5,
|
||||
"filter": "PEAKING",
|
||||
"freq": 5000,
|
||||
"gain": 0.0,
|
||||
"q": 1.24
|
||||
},
|
||||
{
|
||||
"index": 6,
|
||||
"filter": "HIGHSHELF",
|
||||
"freq": 8000,
|
||||
"gain": 0.0,
|
||||
"q": 0.8
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,55 @@
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[switch.cambridge_audio_cxnv2_equalizer-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'switch',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'switch.cambridge_audio_cxnv2_equalizer',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Equalizer',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Equalizer',
|
||||
'platform': 'cambridge_audio',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'equalizer',
|
||||
'unique_id': '0020c2d8-equalizer',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[switch.cambridge_audio_cxnv2_equalizer-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Cambridge Audio CXNv2 Equalizer',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.cambridge_audio_cxnv2_equalizer',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[switch.cambridge_audio_cxnv2_pre_amp-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
|
||||
@@ -58,3 +58,62 @@ async def test_setting_value(
|
||||
blocking=True,
|
||||
)
|
||||
mock_stream_magic_client.set_early_update.assert_called_once_with(False)
|
||||
|
||||
|
||||
async def test_equalizer_switch(
|
||||
hass: HomeAssistant,
|
||||
mock_stream_magic_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test equalizer switch."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
# Test turning equalizer on
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{
|
||||
ATTR_ENTITY_ID: "switch.cambridge_audio_cxnv2_equalizer",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
mock_stream_magic_client.set_equalizer_mode.assert_called_once_with(True)
|
||||
mock_stream_magic_client.set_equalizer_mode.reset_mock()
|
||||
|
||||
# Test turning equalizer off
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{
|
||||
ATTR_ENTITY_ID: "switch.cambridge_audio_cxnv2_equalizer",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
mock_stream_magic_client.set_equalizer_mode.assert_called_once_with(False)
|
||||
|
||||
|
||||
async def test_equalizer_switch_without_user_eq(
|
||||
hass: HomeAssistant,
|
||||
mock_stream_magic_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test that equalizer switch entity is not created when user_eq is None."""
|
||||
# Set user_eq to None to simulate a device without EQ support
|
||||
mock_stream_magic_client.audio.user_eq = None
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
# Verify the equalizer switch entity was not created
|
||||
assert entity_registry.async_get("switch.cambridge_audio_cxnv2_equalizer") is None
|
||||
|
||||
# Verify other switch entities still exist
|
||||
assert entity_registry.async_get("switch.cambridge_audio_cxnv2_pre_amp") is not None
|
||||
assert (
|
||||
entity_registry.async_get("switch.cambridge_audio_cxnv2_early_update")
|
||||
is not None
|
||||
)
|
||||
assert (
|
||||
entity_registry.async_get("switch.cambridge_audio_cxnv2_room_correction")
|
||||
is not None
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user