mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Add Diagnostics to PlayStation Network (#147607)
* Add Diagnostics support to PlayStation_Network * Remove unused constant * minor cleanup * Redact additional data * Redact additional data
This commit is contained in:
parent
263823c92c
commit
efb29d024e
55
homeassistant/components/playstation_network/diagnostics.py
Normal file
55
homeassistant/components/playstation_network/diagnostics.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
"""Diagnostics support for PlayStation Network."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import asdict
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from psnawp_api.models.trophies import PlatformType
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .coordinator import PlaystationNetworkConfigEntry, PlaystationNetworkCoordinator
|
||||||
|
|
||||||
|
TO_REDACT = {
|
||||||
|
"account_id",
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"middleName",
|
||||||
|
"onlineId",
|
||||||
|
"url",
|
||||||
|
"username",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: PlaystationNetworkConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
coordinator: PlaystationNetworkCoordinator = entry.runtime_data
|
||||||
|
|
||||||
|
return {
|
||||||
|
"data": async_redact_data(
|
||||||
|
_serialize_platform_types(asdict(coordinator.data)), TO_REDACT
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _serialize_platform_types(data: Any) -> Any:
|
||||||
|
"""Recursively convert PlatformType enums to strings in dicts and sets."""
|
||||||
|
if isinstance(data, dict):
|
||||||
|
return {
|
||||||
|
(
|
||||||
|
platform.value if isinstance(platform, PlatformType) else platform
|
||||||
|
): _serialize_platform_types(record)
|
||||||
|
for platform, record in data.items()
|
||||||
|
}
|
||||||
|
if isinstance(data, set):
|
||||||
|
return [
|
||||||
|
record.value if isinstance(record, PlatformType) else record
|
||||||
|
for record in data
|
||||||
|
]
|
||||||
|
if isinstance(data, PlatformType):
|
||||||
|
return data.value
|
||||||
|
return data
|
@ -44,7 +44,7 @@ rules:
|
|||||||
|
|
||||||
# Gold
|
# Gold
|
||||||
devices: done
|
devices: done
|
||||||
diagnostics: todo
|
diagnostics: done
|
||||||
discovery-update-info:
|
discovery-update-info:
|
||||||
status: exempt
|
status: exempt
|
||||||
comment: Discovery flow is not applicable for this integration
|
comment: Discovery flow is not applicable for this integration
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_diagnostics
|
||||||
|
dict({
|
||||||
|
'data': dict({
|
||||||
|
'account_id': '**REDACTED**',
|
||||||
|
'active_sessions': dict({
|
||||||
|
'PS5': dict({
|
||||||
|
'format': 'PS5',
|
||||||
|
'media_image_url': 'https://image.api.playstation.com/vulcan/ap/rnd/202211/2222/l8QTN7ThQK3lRBHhB3nX1s7h.png',
|
||||||
|
'platform': 'PS5',
|
||||||
|
'status': 'online',
|
||||||
|
'title_id': 'PPSA07784_00',
|
||||||
|
'title_name': 'STAR WARS Jedi: Survivor™',
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'available': True,
|
||||||
|
'presence': dict({
|
||||||
|
'basicPresence': dict({
|
||||||
|
'availability': 'availableToPlay',
|
||||||
|
'gameTitleInfoList': list([
|
||||||
|
dict({
|
||||||
|
'conceptIconUrl': 'https://image.api.playstation.com/vulcan/ap/rnd/202211/2222/l8QTN7ThQK3lRBHhB3nX1s7h.png',
|
||||||
|
'format': 'PS5',
|
||||||
|
'launchPlatform': 'PS5',
|
||||||
|
'npTitleId': 'PPSA07784_00',
|
||||||
|
'titleName': 'STAR WARS Jedi: Survivor™',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
'primaryPlatformInfo': dict({
|
||||||
|
'onlineStatus': 'online',
|
||||||
|
'platform': 'PS5',
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'profile': dict({
|
||||||
|
'aboutMe': 'Never Gonna Give You Up',
|
||||||
|
'avatars': list([
|
||||||
|
dict({
|
||||||
|
'size': 'xl',
|
||||||
|
'url': '**REDACTED**',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
'isMe': True,
|
||||||
|
'isOfficiallyVerified': False,
|
||||||
|
'isPlus': True,
|
||||||
|
'languages': list([
|
||||||
|
'de-DE',
|
||||||
|
]),
|
||||||
|
'onlineId': '**REDACTED**',
|
||||||
|
'personalDetail': dict({
|
||||||
|
'firstName': '**REDACTED**',
|
||||||
|
'lastName': '**REDACTED**',
|
||||||
|
'profilePictures': list([
|
||||||
|
dict({
|
||||||
|
'size': 'xl',
|
||||||
|
'url': '**REDACTED**',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'registered_platforms': list([
|
||||||
|
'PS5',
|
||||||
|
]),
|
||||||
|
'trophy_summary': dict({
|
||||||
|
'account_id': '**REDACTED**',
|
||||||
|
'earned_trophies': dict({
|
||||||
|
'bronze': 14450,
|
||||||
|
'gold': 11754,
|
||||||
|
'platinum': 1398,
|
||||||
|
'silver': 8722,
|
||||||
|
}),
|
||||||
|
'progress': 19,
|
||||||
|
'tier': 10,
|
||||||
|
'trophy_level': 1079,
|
||||||
|
}),
|
||||||
|
'username': '**REDACTED**',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
# ---
|
28
tests/components/playstation_network/test_diagnostics.py
Normal file
28
tests/components/playstation_network/test_diagnostics.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"""Tests for PlayStation Network diagnostics."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
|
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("mock_psnawpapi")
|
||||||
|
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 (
|
||||||
|
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||||
|
== snapshot
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user