1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-14 23:28:42 +00:00

Add room correction setting to Cambridge Audio (#162743)

Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>
This commit is contained in:
Noah Husby
2026-02-12 17:10:13 -06:00
committed by GitHub
parent 3bcb303ef1
commit 2aa9d22350
6 changed files with 83 additions and 2 deletions

View File

@@ -29,6 +29,9 @@
"state": {
"off": "mdi:volume-low"
}
},
"room_correction": {
"default": "mdi:arrow-oscillating"
}
}
}

View File

@@ -62,6 +62,9 @@
},
"pre_amp": {
"name": "Pre-Amp"
},
"room_correction": {
"name": "Room correction"
}
}
},

View File

@@ -1,8 +1,8 @@
"""Support for Cambridge Audio switch entities."""
from collections.abc import Awaitable, Callable
from dataclasses import dataclass
from typing import Any
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any
from aiostreammagic import StreamMagicClient
@@ -21,10 +21,18 @@ PARALLEL_UPDATES = 0
class CambridgeAudioSwitchEntityDescription(SwitchEntityDescription):
"""Describes Cambridge Audio switch entity."""
load_fn: Callable[[StreamMagicClient], bool] = field(default=lambda _: True)
value_fn: Callable[[StreamMagicClient], bool]
set_value_fn: Callable[[StreamMagicClient, bool], Awaitable[None]]
def room_correction_enabled(client: StreamMagicClient) -> bool:
"""Check if room correction is enabled."""
if TYPE_CHECKING:
assert client.audio.tilt_eq is not None
return client.audio.tilt_eq.enabled
CONTROL_ENTITIES: tuple[CambridgeAudioSwitchEntityDescription, ...] = (
CambridgeAudioSwitchEntityDescription(
key="pre_amp",
@@ -40,6 +48,14 @@ CONTROL_ENTITIES: tuple[CambridgeAudioSwitchEntityDescription, ...] = (
value_fn=lambda client: client.update.early_update,
set_value_fn=lambda client, value: client.set_early_update(value),
),
CambridgeAudioSwitchEntityDescription(
key="room_correction",
translation_key="room_correction",
entity_category=EntityCategory.CONFIG,
load_fn=lambda client: client.audio.tilt_eq is not None,
value_fn=room_correction_enabled,
set_value_fn=lambda client, value: client.set_room_correction_mode(value),
),
)
@@ -49,9 +65,11 @@ async def async_setup_entry(
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up Cambridge Audio switch entities based on a config entry."""
client: StreamMagicClient = entry.runtime_data
async_add_entities(
CambridgeAudioSwitch(entry.runtime_data, description)
for description in CONTROL_ENTITIES
if description.load_fn(client)
)

View File

@@ -4,6 +4,7 @@ from collections.abc import Generator
from unittest.mock import AsyncMock, Mock, patch
from aiostreammagic.models import (
Audio,
AudioOutput,
Display,
Info,
@@ -67,6 +68,7 @@ def mock_stream_magic_client() -> Generator[AsyncMock]:
client.audio_output = AudioOutput.from_json(
load_fixture("get_audio_output.json", DOMAIN)
)
client.audio = Audio.from_json(load_fixture("get_audio.json", DOMAIN))
client.is_connected = Mock(return_value=True)
client.position_last_updated = client.play_state.position
client.unregister_state_update_callbacks.return_value = True

View File

@@ -0,0 +1,6 @@
{
"tilt_eq": {
"enabled": true,
"intensity": 100
}
}

View File

@@ -97,3 +97,52 @@
'state': 'off',
})
# ---
# name: test_all_entities[switch.cambridge_audio_cxnv2_room_correction-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_room_correction',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'object_id_base': 'Room correction',
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Room correction',
'platform': 'cambridge_audio',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'room_correction',
'unique_id': '0020c2d8-room_correction',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[switch.cambridge_audio_cxnv2_room_correction-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Cambridge Audio CXNv2 Room correction',
}),
'context': <ANY>,
'entity_id': 'switch.cambridge_audio_cxnv2_room_correction',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---