Skip to content

Commit 202c907

Browse files
authored
Improve Youtube integration (home-assistant#93683)
* Fix feedback * Fix feedback
1 parent 41882d8 commit 202c907

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

homeassistant/components/youtube/coordinator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
def get_upload_playlist_id(channel_id: str) -> str:
3232
"""Return the playlist id with the uploads of the channel.
3333
34-
Replacing the UC in the channel id (UCxxxxxxxxxxxx) with UU is the way to do it without extra request (UUxxxxxxxxxxxx).
34+
Replacing the UC in the channel id (UCxxxxxxxxxxxx) with UU is
35+
the way to do it without extra request (UUxxxxxxxxxxxx).
3536
"""
3637
return channel_id.replace("UC", "UU", 1)
3738

homeassistant/components/youtube/entity.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
from homeassistant.const import ATTR_ID
77
from homeassistant.helpers.device_registry import DeviceEntryType
8-
from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription
8+
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
9+
from homeassistant.helpers.update_coordinator import CoordinatorEntity
910

1011
from .const import ATTR_TITLE, DOMAIN, MANUFACTURER
1112
from .coordinator import YouTubeDataUpdateCoordinator
1213

1314

14-
class YouTubeChannelEntity(Entity):
15+
class YouTubeChannelEntity(CoordinatorEntity):
1516
"""An HA implementation for YouTube entity."""
1617

1718
_attr_has_entity_name = True
@@ -23,6 +24,7 @@ def __init__(
2324
channel: dict[str, Any],
2425
) -> None:
2526
"""Initialize a Google Mail entity."""
27+
super().__init__(coordinator)
2628
self.entity_description = description
2729
self._attr_unique_id = (
2830
f"{coordinator.config_entry.entry_id}_{channel[ATTR_ID]}_{description.key}"

homeassistant/components/youtube/strings.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@
1919
}
2020
}
2121
},
22-
"options": {
23-
"step": {
24-
"init": {
25-
"description": "Select the channels you want to add.",
26-
"data": {
27-
"channels": "YouTube channels"
28-
}
29-
}
30-
}
31-
},
3222
"entity": {
3323
"sensor": {
3424
"latest_upload": {

tests/components/youtube/test_sensor.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"""Sensor tests for the YouTube integration."""
2+
from datetime import timedelta
23
from unittest.mock import patch
34

45
from google.auth.exceptions import RefreshError
56

67
from homeassistant import config_entries
7-
from homeassistant.components.youtube import COORDINATOR, DOMAIN
8+
from homeassistant.components.youtube import DOMAIN
89
from homeassistant.core import HomeAssistant
10+
from homeassistant.util import dt
911

12+
from ...common import async_fire_time_changed
1013
from .conftest import TOKEN, ComponentSetup
1114

1215

@@ -40,8 +43,8 @@ async def test_sensor_reauth_trigger(
4043
await setup_integration()
4144

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

4750
flows = hass.config_entries.flow.async_progress()

0 commit comments

Comments
 (0)