mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Move tautulli base entity to separate module (#126528)
This commit is contained in:
parent
52de26e67b
commit
ef39ee1d5d
@ -2,17 +2,13 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pytautulli import PyTautulli, PyTautulliApiUser, PyTautulliHostConfiguration
|
from pytautulli import PyTautulli, PyTautulliHostConfiguration
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL, Platform
|
from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
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 .const import DEFAULT_NAME, DOMAIN
|
|
||||||
from .coordinator import TautulliDataUpdateCoordinator
|
from .coordinator import TautulliDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS = [Platform.SENSOR]
|
PLATFORMS = [Platform.SENSOR]
|
||||||
@ -42,29 +38,3 @@ async def async_setup_entry(hass: HomeAssistant, entry: TautulliConfigEntry) ->
|
|||||||
async def async_unload_entry(hass: HomeAssistant, entry: TautulliConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: TautulliConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
|
|
||||||
class TautulliEntity(CoordinatorEntity[TautulliDataUpdateCoordinator]):
|
|
||||||
"""Defines a base Tautulli entity."""
|
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
coordinator: TautulliDataUpdateCoordinator,
|
|
||||||
description: EntityDescription,
|
|
||||||
user: PyTautulliApiUser | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Initialize the Tautulli entity."""
|
|
||||||
super().__init__(coordinator)
|
|
||||||
entry_id = coordinator.config_entry.entry_id
|
|
||||||
self._attr_unique_id = f"{entry_id}_{description.key}"
|
|
||||||
self.entity_description = description
|
|
||||||
self.user = user
|
|
||||||
self._attr_device_info = DeviceInfo(
|
|
||||||
configuration_url=coordinator.host_configuration.base_url,
|
|
||||||
entry_type=DeviceEntryType.SERVICE,
|
|
||||||
identifiers={(DOMAIN, user.user_id if user else entry_id)},
|
|
||||||
manufacturer=DEFAULT_NAME,
|
|
||||||
name=user.username if user else DEFAULT_NAME,
|
|
||||||
)
|
|
||||||
|
38
homeassistant/components/tautulli/entity.py
Normal file
38
homeassistant/components/tautulli/entity.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
"""The Tautulli integration."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pytautulli import PyTautulliApiUser
|
||||||
|
|
||||||
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
|
from homeassistant.helpers.entity import EntityDescription
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from .const import DEFAULT_NAME, DOMAIN
|
||||||
|
from .coordinator import TautulliDataUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
|
class TautulliEntity(CoordinatorEntity[TautulliDataUpdateCoordinator]):
|
||||||
|
"""Defines a base Tautulli entity."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: TautulliDataUpdateCoordinator,
|
||||||
|
description: EntityDescription,
|
||||||
|
user: PyTautulliApiUser | None = None,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the Tautulli entity."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
entry_id = coordinator.config_entry.entry_id
|
||||||
|
self._attr_unique_id = f"{entry_id}_{description.key}"
|
||||||
|
self.entity_description = description
|
||||||
|
self.user = user
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
configuration_url=coordinator.host_configuration.base_url,
|
||||||
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
|
identifiers={(DOMAIN, user.user_id if user else entry_id)},
|
||||||
|
manufacturer=DEFAULT_NAME,
|
||||||
|
name=user.username if user else DEFAULT_NAME,
|
||||||
|
)
|
@ -26,9 +26,10 @@ from homeassistant.helpers.entity import EntityDescription
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
||||||
|
|
||||||
from . import TautulliConfigEntry, TautulliEntity
|
from . import TautulliConfigEntry
|
||||||
from .const import ATTR_TOP_USER, DOMAIN
|
from .const import ATTR_TOP_USER, DOMAIN
|
||||||
from .coordinator import TautulliDataUpdateCoordinator
|
from .coordinator import TautulliDataUpdateCoordinator
|
||||||
|
from .entity import TautulliEntity
|
||||||
|
|
||||||
|
|
||||||
def get_top_stats(
|
def get_top_stats(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user