Move lidarr base entity to separate module (#126492)

This commit is contained in:
epenet 2024-09-23 12:47:53 +02:00 committed by GitHub
parent acd3b2d732
commit da3f18839a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 25 deletions

View File

@ -12,17 +12,13 @@ from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL, Platfor
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.helpers.device_registry import DeviceEntryType
from .const import DEFAULT_NAME, DOMAIN
from .coordinator import (
DiskSpaceDataUpdateCoordinator,
LidarrDataUpdateCoordinator,
QueueDataUpdateCoordinator,
StatusDataUpdateCoordinator,
T,
WantedDataUpdateCoordinator,
)
@ -80,22 +76,3 @@ async def async_setup_entry(hass: HomeAssistant, entry: LidarrConfigEntry) -> bo
async def async_unload_entry(hass: HomeAssistant, entry: LidarrConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
class LidarrEntity(CoordinatorEntity[LidarrDataUpdateCoordinator[T]]):
"""Defines a base Lidarr entity."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: LidarrDataUpdateCoordinator[T],
description: EntityDescription,
) -> None:
"""Initialize the Lidarr entity."""
super().__init__(coordinator)
self.entity_description = description
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{description.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, coordinator.config_entry.entry_id)}
)

View File

@ -0,0 +1,29 @@
"""The Lidarr component."""
from __future__ import annotations
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .coordinator import LidarrDataUpdateCoordinator, T
class LidarrEntity(CoordinatorEntity[LidarrDataUpdateCoordinator[T]]):
"""Defines a base Lidarr entity."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: LidarrDataUpdateCoordinator[T],
description: EntityDescription,
) -> None:
"""Initialize the Lidarr entity."""
super().__init__(coordinator)
self.entity_description = description
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{description.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, coordinator.config_entry.entry_id)}
)

View File

@ -18,9 +18,10 @@ from homeassistant.const import UnitOfInformation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import LidarrConfigEntry, LidarrEntity
from . import LidarrConfigEntry
from .const import BYTE_SIZES
from .coordinator import LidarrDataUpdateCoordinator, T
from .entity import LidarrEntity
def get_space(data: list[LidarrRootFolder], name: str) -> str: