Files
core/homeassistant/components/youtube/diagnostics.py
T

38 lines
1.1 KiB
Python

"""Diagnostics support for YouTube."""
from typing import Any
from homeassistant.core import HomeAssistant
from .const import (
ATTR_DESCRIPTION,
ATTR_LATEST_SHORT,
ATTR_LATEST_VIDEO,
ATTR_LATEST_VIDEO_NON_SHORT,
)
from .coordinator import YouTubeConfigEntry
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: YouTubeConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinator = entry.runtime_data
sensor_data: dict[str, Any] = {}
for channel_id, channel_data in coordinator.data.items():
channel_copy = dict(channel_data)
# Strip verbose description field from all video entries.
for attr in (
ATTR_LATEST_VIDEO,
ATTR_LATEST_SHORT,
ATTR_LATEST_VIDEO_NON_SHORT,
):
if video := channel_copy.get(attr):
channel_copy[attr] = {
key: value
for key, value in video.items()
if key != ATTR_DESCRIPTION
}
sensor_data[channel_id] = channel_copy
return sensor_data