Centralize lidarr device creation (#119822)

This commit is contained in:
Joost Lekkerkerker 2024-06-18 12:10:11 +02:00 committed by GitHub
parent 0ff0022877
commit 9128dc198a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 12 deletions

View file

@ -10,6 +10,7 @@ from aiopyarr.models.host_configuration import PyArrHostConfiguration
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL, Platform
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
@ -58,14 +59,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: LidarrConfigEntry) -> bo
status=StatusDataUpdateCoordinator(hass, host_configuration, lidarr),
wanted=WantedDataUpdateCoordinator(hass, host_configuration, lidarr),
)
# Temporary, until we add diagnostic entities
_version = None
for field in fields(data):
coordinator = getattr(data, field.name)
await coordinator.async_config_entry_first_refresh()
if isinstance(coordinator, StatusDataUpdateCoordinator):
_version = coordinator.data
coordinator.system_version = _version
device_registry = dr.async_get(hass)
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
configuration_url=entry.data[CONF_URL],
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, entry.entry_id)},
manufacturer=DEFAULT_NAME,
sw_version=data.status.data,
)
entry.runtime_data = data
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
@ -92,10 +97,5 @@ class LidarrEntity(CoordinatorEntity[LidarrDataUpdateCoordinator[T]]):
self.entity_description = description
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{description.key}"
self._attr_device_info = DeviceInfo(
configuration_url=coordinator.host_configuration.base_url,
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
manufacturer=DEFAULT_NAME,
name=coordinator.config_entry.title,
sw_version=coordinator.system_version,
identifiers={(DOMAIN, coordinator.config_entry.entry_id)}
)

View file

@ -40,7 +40,6 @@ class LidarrDataUpdateCoordinator(DataUpdateCoordinator[T], Generic[T], ABC):
)
self.api_client = api_client
self.host_configuration = host_configuration
self.system_version: str | None = None
async def _async_update_data(self) -> T:
"""Get the latest data from Lidarr."""