1 """DataUpdateCoordinator for the YouTube integration."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 from youtubeaio.helper
import first
9 from youtubeaio.types
import UnauthorizedError, YouTubeBackendError
17 from .
import AsyncConfigEntryAuth
22 ATTR_SUBSCRIBER_COUNT,
34 """A YouTube Data Update Coordinator."""
36 config_entry: ConfigEntry
38 def __init__(self, hass: HomeAssistant, auth: AsyncConfigEntryAuth) ->
None:
39 """Initialize the YouTube data coordinator."""
51 channel_ids = self.
config_entryconfig_entry.options[CONF_CHANNELS]
53 async
for channel
in youtube.get_channels(channel_ids):
55 youtube.get_playlist_items(channel.upload_playlist_id, 1)
60 ATTR_PUBLISHED_AT: video.snippet.added_at,
61 ATTR_TITLE: video.snippet.title,
62 ATTR_DESCRIPTION: video.snippet.description,
63 ATTR_THUMBNAIL: video.snippet.thumbnails.get_highest_quality().url,
64 ATTR_VIDEO_ID: video.content_details.video_id,
66 res[channel.channel_id] = {
67 ATTR_ID: channel.channel_id,
68 ATTR_TITLE: channel.snippet.title,
69 ATTR_ICON: channel.snippet.thumbnails.get_highest_quality().url,
70 ATTR_LATEST_VIDEO: latest_video,
71 ATTR_SUBSCRIBER_COUNT: channel.statistics.subscriber_count,
72 ATTR_TOTAL_VIEWS: channel.statistics.view_count,
74 except UnauthorizedError
as err:
75 raise ConfigEntryAuthFailed
from err
76 except YouTubeBackendError
as err:
77 raise UpdateFailed(
"Couldn't connect to YouTube")
from err
dict[str, Any] _async_update_data(self)
None __init__(self, HomeAssistant hass, AsyncConfigEntryAuth auth)
str get_resource(str domain_name, ConfigType domain_data)