mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Add diagnostics to YouTube (#96975)
This commit is contained in:
parent
e4d65cbae1
commit
33c2fc008a
24
homeassistant/components/youtube/diagnostics.py
Normal file
24
homeassistant/components/youtube/diagnostics.py
Normal file
@ -0,0 +1,24 @@
|
||||
"""Diagnostics support for YouTube."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import ATTR_DESCRIPTION, ATTR_LATEST_VIDEO, COORDINATOR, DOMAIN
|
||||
from .coordinator import YouTubeDataUpdateCoordinator
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: YouTubeDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
||||
COORDINATOR
|
||||
]
|
||||
sensor_data = {}
|
||||
for channel_id, channel_data in coordinator.data.items():
|
||||
channel_data.get(ATTR_LATEST_VIDEO, {}).pop(ATTR_DESCRIPTION)
|
||||
sensor_data[channel_id] = channel_data
|
||||
return sensor_data
|
17
tests/components/youtube/snapshots/test_diagnostics.ambr
Normal file
17
tests/components/youtube/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,17 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'UC_x5XG1OV2P6uZZ5FSM9Ttw': dict({
|
||||
'icon': 'https://yt3.ggpht.com/fca_HuJ99xUxflWdex0XViC3NfctBFreIl8y4i9z411asnGTWY-Ql3MeH_ybA4kNaOjY7kyA=s800-c-k-c0x00ffffff-no-rj',
|
||||
'id': 'UC_x5XG1OV2P6uZZ5FSM9Ttw',
|
||||
'latest_video': dict({
|
||||
'published_at': '2023-05-11T00:20:46Z',
|
||||
'thumbnail': 'https://i.ytimg.com/vi/wysukDrMdqU/sddefault.jpg',
|
||||
'title': "What's new in Google Home in less than 1 minute",
|
||||
'video_id': 'wysukDrMdqU',
|
||||
}),
|
||||
'subscriber_count': 2290000,
|
||||
'title': 'Google for Developers',
|
||||
}),
|
||||
})
|
||||
# ---
|
23
tests/components/youtube/test_diagnostics.py
Normal file
23
tests/components/youtube/test_diagnostics.py
Normal file
@ -0,0 +1,23 @@
|
||||
"""Tests for the diagnostics data provided by the YouTube integration."""
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.youtube.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import ComponentSetup
|
||||
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
setup_integration: ComponentSetup,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
await setup_integration()
|
||||
entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == snapshot
|
Loading…
x
Reference in New Issue
Block a user