2021-06-11 06:48:20 -05:00
|
|
|
"""Base Entity for Sonarr."""
|
2022-10-07 18:25:16 -04:00
|
|
|
from __future__ import annotations
|
2021-06-11 06:48:20 -05:00
|
|
|
|
2021-11-22 19:14:15 +02:00
|
|
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
2022-10-07 18:25:16 -04:00
|
|
|
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
|
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
2021-06-11 06:48:20 -05:00
|
|
|
|
2022-10-07 21:53:48 -04:00
|
|
|
from .const import DEFAULT_NAME, DOMAIN
|
2022-10-07 18:25:16 -04:00
|
|
|
from .coordinator import SonarrDataT, SonarrDataUpdateCoordinator
|
2021-06-11 06:48:20 -05:00
|
|
|
|
|
|
|
|
2022-10-07 18:25:16 -04:00
|
|
|
class SonarrEntity(CoordinatorEntity[SonarrDataUpdateCoordinator[SonarrDataT]]):
|
2021-06-11 06:48:20 -05:00
|
|
|
"""Defines a base Sonarr entity."""
|
|
|
|
|
2022-10-07 21:53:48 -04:00
|
|
|
_attr_has_entity_name = True
|
|
|
|
|
2021-06-11 06:48:20 -05:00
|
|
|
def __init__(
|
|
|
|
self,
|
2022-10-07 18:25:16 -04:00
|
|
|
coordinator: SonarrDataUpdateCoordinator[SonarrDataT],
|
|
|
|
description: EntityDescription,
|
2021-06-11 06:48:20 -05:00
|
|
|
) -> None:
|
|
|
|
"""Initialize the Sonarr entity."""
|
2022-10-07 18:25:16 -04:00
|
|
|
super().__init__(coordinator)
|
|
|
|
self.coordinator = coordinator
|
|
|
|
self.entity_description = description
|
|
|
|
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{description.key}"
|
2021-06-11 06:48:20 -05:00
|
|
|
|
|
|
|
@property
|
2022-10-07 13:08:08 -04:00
|
|
|
def device_info(self) -> DeviceInfo:
|
2021-06-11 06:48:20 -05:00
|
|
|
"""Return device information about the application."""
|
2021-10-22 17:40:13 +02:00
|
|
|
return DeviceInfo(
|
2022-10-07 18:25:16 -04:00
|
|
|
configuration_url=self.coordinator.host_configuration.base_url,
|
2021-11-22 19:14:15 +02:00
|
|
|
entry_type=DeviceEntryType.SERVICE,
|
2022-10-07 18:25:16 -04:00
|
|
|
identifiers={(DOMAIN, self.coordinator.config_entry.entry_id)},
|
2022-10-07 21:53:48 -04:00
|
|
|
manufacturer=DEFAULT_NAME,
|
|
|
|
name=DEFAULT_NAME,
|
2022-10-07 18:25:16 -04:00
|
|
|
sw_version=self.coordinator.system_version,
|
2021-10-22 17:40:13 +02:00
|
|
|
)
|