mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add diagnostics to Bluesound (#195680)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
fcc4535057
commit
58855d8f2c
@@ -0,0 +1,31 @@
|
||||
"""Diagnostics support for Bluesound."""
|
||||
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import BluesoundConfigEntry
|
||||
|
||||
TO_REDACT = {"mac", "stream_url", "unique_id", "url"}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: BluesoundConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator = config_entry.runtime_data.coordinator
|
||||
data = coordinator.data
|
||||
|
||||
return async_redact_data(
|
||||
{
|
||||
"config_entry": config_entry.as_dict(),
|
||||
"last_update_success": coordinator.last_update_success,
|
||||
"sync_status": asdict(data.sync_status),
|
||||
"status": asdict(data.status),
|
||||
"presets": [asdict(preset) for preset in data.presets],
|
||||
"inputs": [asdict(input_) for input_ in data.inputs],
|
||||
},
|
||||
TO_REDACT,
|
||||
)
|
||||
@@ -47,7 +47,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery: done
|
||||
discovery-update-info: done
|
||||
docs-data-update: done
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'config_entry': dict({
|
||||
'data': dict({
|
||||
'host': '1.1.1.1',
|
||||
'port': 11000,
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'discovery_keys': dict({
|
||||
}),
|
||||
'domain': 'bluesound',
|
||||
'minor_version': 1,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'subentries': list([
|
||||
]),
|
||||
'title': 'Mock Title',
|
||||
'unique_id': '**REDACTED**',
|
||||
'version': 1,
|
||||
}),
|
||||
'inputs': list([
|
||||
dict({
|
||||
'id': '1',
|
||||
'image': 'image1',
|
||||
'text': 'input1',
|
||||
'url': '**REDACTED**',
|
||||
}),
|
||||
dict({
|
||||
'id': '2',
|
||||
'image': 'image2',
|
||||
'text': 'input2',
|
||||
'url': '**REDACTED**',
|
||||
}),
|
||||
dict({
|
||||
'id': None,
|
||||
'image': 'image3',
|
||||
'text': 'input3',
|
||||
'url': '**REDACTED**',
|
||||
}),
|
||||
dict({
|
||||
'id': '4',
|
||||
'image': 'image4',
|
||||
'text': None,
|
||||
'url': '**REDACTED**',
|
||||
}),
|
||||
dict({
|
||||
'id': None,
|
||||
'image': 'image5',
|
||||
'text': None,
|
||||
'url': '**REDACTED**',
|
||||
}),
|
||||
]),
|
||||
'last_update_success': True,
|
||||
'presets': list([
|
||||
dict({
|
||||
'id': 1,
|
||||
'image': 'image1',
|
||||
'name': 'preset1',
|
||||
'url': '**REDACTED**',
|
||||
'volume': None,
|
||||
}),
|
||||
dict({
|
||||
'id': 2,
|
||||
'image': 'image2',
|
||||
'name': 'preset2',
|
||||
'url': '**REDACTED**',
|
||||
'volume': None,
|
||||
}),
|
||||
]),
|
||||
'status': dict({
|
||||
'album': 'album',
|
||||
'artist': 'artist',
|
||||
'can_seek': False,
|
||||
'etag': 'etag',
|
||||
'group_name': None,
|
||||
'group_volume': None,
|
||||
'image': None,
|
||||
'indexing': False,
|
||||
'input_id': None,
|
||||
'mute': False,
|
||||
'mute_volume': None,
|
||||
'mute_volume_db': None,
|
||||
'name': 'song',
|
||||
'seconds': 2,
|
||||
'service': None,
|
||||
'shuffle': False,
|
||||
'sleep': 0,
|
||||
'state': 'play',
|
||||
'stream_url': '**REDACTED**',
|
||||
'total_seconds': 123.1,
|
||||
'volume': 10,
|
||||
'volume_db': 22.3,
|
||||
}),
|
||||
'sync_status': dict({
|
||||
'brand': 'brand',
|
||||
'etag': 'etag',
|
||||
'followers': None,
|
||||
'group': None,
|
||||
'id': '1.1.1.1:11000',
|
||||
'image': 'invalid_url',
|
||||
'initialized': True,
|
||||
'leader': None,
|
||||
'mac': '**REDACTED**',
|
||||
'model': 'model',
|
||||
'model_name': 'model-name',
|
||||
'mute_volume': None,
|
||||
'mute_volume_db': None,
|
||||
'name': 'player-name1111',
|
||||
'volume': 50,
|
||||
'volume_db': 0.5,
|
||||
'zone': None,
|
||||
'zone_follower': None,
|
||||
'zone_leader': None,
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,37 @@
|
||||
"""Tests for the Bluesound diagnostics."""
|
||||
|
||||
import dataclasses
|
||||
|
||||
from pytest_homeassistant.common import MockConfigEntry
|
||||
from pytest_homeassistant.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from pytest_homeassistant.typing import ClientSessionGenerator
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import PlayerMocks
|
||||
|
||||
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
player_mocks: PlayerMocks,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
status_mock = player_mocks.player_data.status_long_polling_mock
|
||||
status_mock.set(
|
||||
dataclasses.replace(
|
||||
status_mock.get(),
|
||||
stream_url="http://homeassistant.local:8123/api/media_source/local_source/media/song.mp3?authSig=secret",
|
||||
)
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||
|
||||
assert result == snapshot(exclude=props("entry_id", "created_at", "modified_at"))
|
||||
Reference in New Issue
Block a user