mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Add diagnostics platform to Xbox integration (#156662)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
"""Diagnostics platform for the Xbox integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import XboxConfigEntry
|
||||
|
||||
TO_REDACT = {
|
||||
"bio",
|
||||
"display_name",
|
||||
"display_pic_raw",
|
||||
"gamertag",
|
||||
"linked_accounts",
|
||||
"location",
|
||||
"modern_gamertag_suffix",
|
||||
"modern_gamertag",
|
||||
"real_name",
|
||||
"unique_modern_gamertag",
|
||||
"xuid",
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: XboxConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
|
||||
coordinator = config_entry.runtime_data.status
|
||||
consoles_coordinator = config_entry.runtime_data.consoles
|
||||
|
||||
presence = [
|
||||
async_redact_data(person.model_dump(), TO_REDACT)
|
||||
for person in coordinator.data.presence.values()
|
||||
]
|
||||
consoles_status = [
|
||||
{
|
||||
"status": console.status.model_dump(),
|
||||
"app_details": (
|
||||
console.app_details.model_dump() if console.app_details else None
|
||||
),
|
||||
}
|
||||
for console in coordinator.data.consoles.values()
|
||||
]
|
||||
consoles_list = consoles_coordinator.data.model_dump()
|
||||
title_info = [title.model_dump() for title in coordinator.data.title_info.values()]
|
||||
|
||||
return {
|
||||
"consoles_status": consoles_status,
|
||||
"consoles_list": consoles_list,
|
||||
"presence": presence,
|
||||
"title_info": title_info,
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
"""Test for diagnostics platform of the Xbox integration."""
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
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
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("xbox_live_client")
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||
== snapshot
|
||||
)
|
||||
Reference in New Issue
Block a user