mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Add Bang & Olufsen diagnostics (#131538)
* Add diagnostics * Add tests for diagnostics * Add media_player diagnostics * Use media_player entity's state instead of registryentry * Update tests * Reorganize code Remove context from media_player state * Fix dict being read only Simplify naming Update test snapshot * Update test snapshot
This commit is contained in:
parent
40a4ff1c84
commit
a97eeaf189
40
homeassistant/components/bang_olufsen/diagnostics.py
Normal file
40
homeassistant/components/bang_olufsen/diagnostics.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
"""Support for Bang & Olufsen diagnostics."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
import homeassistant.helpers.entity_registry as er
|
||||||
|
|
||||||
|
from . import BangOlufsenConfigEntry
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, config_entry: BangOlufsenConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
|
||||||
|
data: dict = {
|
||||||
|
"config_entry": config_entry.as_dict(),
|
||||||
|
"websocket_connected": config_entry.runtime_data.client.websocket_connected,
|
||||||
|
}
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert config_entry.unique_id
|
||||||
|
|
||||||
|
# Add media_player entity's state
|
||||||
|
entity_registry = er.async_get(hass)
|
||||||
|
if entity_id := entity_registry.async_get_entity_id(
|
||||||
|
MEDIA_PLAYER_DOMAIN, DOMAIN, config_entry.unique_id
|
||||||
|
):
|
||||||
|
if state := hass.states.get(entity_id):
|
||||||
|
state_dict = dict(state.as_dict())
|
||||||
|
|
||||||
|
# Remove context as it is not relevant
|
||||||
|
state_dict.pop("context")
|
||||||
|
data["media_player"] = state_dict
|
||||||
|
|
||||||
|
return data
|
@ -0,0 +1,67 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_async_get_config_entry_diagnostics
|
||||||
|
dict({
|
||||||
|
'config_entry': dict({
|
||||||
|
'data': dict({
|
||||||
|
'host': '192.168.0.1',
|
||||||
|
'jid': '1111.1111111.11111111@products.bang-olufsen.com',
|
||||||
|
'model': 'Beosound Balance',
|
||||||
|
'name': 'Beosound Balance-11111111',
|
||||||
|
}),
|
||||||
|
'disabled_by': None,
|
||||||
|
'discovery_keys': dict({
|
||||||
|
}),
|
||||||
|
'domain': 'bang_olufsen',
|
||||||
|
'minor_version': 1,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'pref_disable_new_entities': False,
|
||||||
|
'pref_disable_polling': False,
|
||||||
|
'source': 'user',
|
||||||
|
'title': 'Beosound Balance-11111111',
|
||||||
|
'unique_id': '11111111',
|
||||||
|
'version': 1,
|
||||||
|
}),
|
||||||
|
'media_player': dict({
|
||||||
|
'attributes': dict({
|
||||||
|
'beolink': dict({
|
||||||
|
'listeners': dict({
|
||||||
|
'Lego room Balance': '1111.1111111.33333333@products.bang-olufsen.com',
|
||||||
|
'Lounge room Balance': '1111.1111111.44444444@products.bang-olufsen.com',
|
||||||
|
}),
|
||||||
|
'peers': dict({
|
||||||
|
'Lego room Balance': '1111.1111111.33333333@products.bang-olufsen.com',
|
||||||
|
'Lounge room Balance': '1111.1111111.44444444@products.bang-olufsen.com',
|
||||||
|
}),
|
||||||
|
'self': dict({
|
||||||
|
'Living room Balance': '1111.1111111.11111111@products.bang-olufsen.com',
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'device_class': 'speaker',
|
||||||
|
'entity_picture_local': None,
|
||||||
|
'friendly_name': 'Living room Balance',
|
||||||
|
'group_members': list([
|
||||||
|
'media_player.beosound_balance_11111111',
|
||||||
|
'listener_not_in_hass-1111.1111111.33333333@products.bang-olufsen.com',
|
||||||
|
'listener_not_in_hass-1111.1111111.44444444@products.bang-olufsen.com',
|
||||||
|
]),
|
||||||
|
'media_content_type': 'music',
|
||||||
|
'sound_mode': 'Test Listening Mode (123)',
|
||||||
|
'sound_mode_list': list([
|
||||||
|
'Test Listening Mode (123)',
|
||||||
|
'Test Listening Mode (234)',
|
||||||
|
'Test Listening Mode 2 (345)',
|
||||||
|
]),
|
||||||
|
'source_list': list([
|
||||||
|
'Tidal',
|
||||||
|
'Line-In',
|
||||||
|
'HDMI A',
|
||||||
|
]),
|
||||||
|
'supported_features': 2095933,
|
||||||
|
}),
|
||||||
|
'entity_id': 'media_player.beosound_balance_11111111',
|
||||||
|
'state': 'playing',
|
||||||
|
}),
|
||||||
|
'websocket_connected': False,
|
||||||
|
})
|
||||||
|
# ---
|
41
tests/components/bang_olufsen/test_diagnostics.py
Normal file
41
tests/components/bang_olufsen/test_diagnostics.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
"""Test bang_olufsen config entry diagnostics."""
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
from syrupy.filters import props
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
mock_mozart_client: AsyncMock,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test config entry diagnostics."""
|
||||||
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
|
|
||||||
|
result = await get_diagnostics_for_config_entry(
|
||||||
|
hass, hass_client, mock_config_entry
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result == snapshot(
|
||||||
|
exclude=props(
|
||||||
|
"created_at",
|
||||||
|
"entry_id",
|
||||||
|
"id",
|
||||||
|
"last_changed",
|
||||||
|
"last_reported",
|
||||||
|
"last_updated",
|
||||||
|
"media_position_updated_at",
|
||||||
|
"modified_at",
|
||||||
|
)
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user