Skip to content

Commit

Permalink
Update diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
mj23000 committed Nov 26, 2024
1 parent d8fa4ec commit a3124bf
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions custom_components/bang_olufsen/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,39 @@

from __future__ import annotations

from typing import Any
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."""

return {
"websocket_connected": config_entry.runtime_data.client.websocket_connected,
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 comments on commit a3124bf

Please sign in to comment.