Improve Youtube integration (#93683)

* Fix feedback

* Fix feedback
This commit is contained in:
Joost Lekkerkerker 2023-05-28 10:52:30 +02:00 committed by GitHub
parent 41882d833d
commit 202c9071a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 16 deletions

View File

@ -31,7 +31,8 @@ from .const import (
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)

View File

@ -5,13 +5,14 @@ from typing import Any
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
@ -23,6 +24,7 @@ class YouTubeChannelEntity(Entity):
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}"

View File

@ -19,16 +19,6 @@
}
}
},
"options": {
"step": {
"init": {
"description": "Select the channels you want to add.",
"data": {
"channels": "YouTube channels"
}
}
}
},
"entity": {
"sensor": {
"latest_upload": {

View File

@ -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
@ -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()