Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Youtube integration #93683

Merged
merged 2 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/youtube/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
def get_upload_playlist_id(channel_id: str) -> str:
"""Return the playlist id with the uploads of the channel.

Replacing the UC in the channel id (UCxxxxxxxxxxxx) with UU is the way to do it without extra request (UUxxxxxxxxxxxx).
Replacing the UC in the channel id (UCxxxxxxxxxxxx) with UU is
the way to do it without extra request (UUxxxxxxxxxxxx).
"""
return channel_id.replace("UC", "UU", 1)

Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/youtube/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

from homeassistant.const import ATTR_ID
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import ATTR_TITLE, DOMAIN, MANUFACTURER
from .coordinator import YouTubeDataUpdateCoordinator


class YouTubeChannelEntity(Entity):
class YouTubeChannelEntity(CoordinatorEntity):
"""An HA implementation for YouTube entity."""

_attr_has_entity_name = True
Expand All @@ -23,6 +24,7 @@ def __init__(
channel: dict[str, Any],
) -> None:
"""Initialize a Google Mail entity."""
super().__init__(coordinator)
self.entity_description = description
self._attr_unique_id = (
f"{coordinator.config_entry.entry_id}_{channel[ATTR_ID]}_{description.key}"
Expand Down
10 changes: 0 additions & 10 deletions homeassistant/components/youtube/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@
}
}
},
"options": {
"step": {
"init": {
"description": "Select the channels you want to add.",
"data": {
"channels": "YouTube channels"
}
}
}
},
"entity": {
"sensor": {
"latest_upload": {
Expand Down
9 changes: 6 additions & 3 deletions tests/components/youtube/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""Sensor tests for the YouTube integration."""
from datetime import timedelta
from unittest.mock import patch

from google.auth.exceptions import RefreshError

from homeassistant import config_entries
from homeassistant.components.youtube import COORDINATOR, DOMAIN
from homeassistant.components.youtube import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.util import dt

from ...common import async_fire_time_changed
from .conftest import TOKEN, ComponentSetup


Expand Down Expand Up @@ -40,8 +43,8 @@ async def test_sensor_reauth_trigger(
await setup_integration()

with patch(TOKEN, side_effect=RefreshError):
entry = hass.config_entries.async_entries(DOMAIN)[0]
await hass.data[DOMAIN][entry.entry_id][COORDINATOR].async_refresh()
future = dt.utcnow() + timedelta(minutes=15)
async_fire_time_changed(hass, future)
await hass.async_block_till_done()

flows = hass.config_entries.flow.async_progress()
Expand Down