Move deluge base entity to separate module (#126479)

This commit is contained in:
epenet 2024-09-23 08:54:28 +02:00 committed by GitHub
parent 7b9f295071
commit 432d44c20d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 26 deletions

View file

@ -17,10 +17,8 @@ from homeassistant.const import (
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import CONF_WEB_PORT, DEFAULT_NAME, DOMAIN
from .const import CONF_WEB_PORT
from .coordinator import DelugeDataUpdateCoordinator
PLATFORMS = [Platform.SENSOR, Platform.SWITCH]
@ -61,24 +59,3 @@ async def async_setup_entry(hass: HomeAssistant, entry: DelugeConfigEntry) -> bo
async def async_unload_entry(hass: HomeAssistant, entry: DelugeConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
class DelugeEntity(CoordinatorEntity[DelugeDataUpdateCoordinator]):
"""Representation of a Deluge entity."""
_attr_has_entity_name = True
def __init__(self, coordinator: DelugeDataUpdateCoordinator) -> None:
"""Initialize a Deluge entity."""
super().__init__(coordinator)
self._server_unique_id = coordinator.config_entry.entry_id
self._attr_device_info = DeviceInfo(
configuration_url=(
f"http://{coordinator.api.host}:{coordinator.api.web_port}"
),
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
manufacturer=DEFAULT_NAME,
name=DEFAULT_NAME,
sw_version=coordinator.api.deluge_version,
)

View file

@ -0,0 +1,30 @@
"""The Deluge integration."""
from __future__ import annotations
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DEFAULT_NAME, DOMAIN
from .coordinator import DelugeDataUpdateCoordinator
class DelugeEntity(CoordinatorEntity[DelugeDataUpdateCoordinator]):
"""Representation of a Deluge entity."""
_attr_has_entity_name = True
def __init__(self, coordinator: DelugeDataUpdateCoordinator) -> None:
"""Initialize a Deluge entity."""
super().__init__(coordinator)
self._server_unique_id = coordinator.config_entry.entry_id
self._attr_device_info = DeviceInfo(
configuration_url=(
f"http://{coordinator.api.host}:{coordinator.api.web_port}"
),
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
manufacturer=DEFAULT_NAME,
name=DEFAULT_NAME,
sw_version=coordinator.api.deluge_version,
)

View file

@ -17,9 +17,10 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from . import DelugeConfigEntry, DelugeEntity
from . import DelugeConfigEntry
from .const import CURRENT_STATUS, DATA_KEYS, DOWNLOAD_SPEED, UPLOAD_SPEED
from .coordinator import DelugeDataUpdateCoordinator
from .entity import DelugeEntity
def get_state(data: dict[str, float], key: str) -> str | float:

View file

@ -9,8 +9,9 @@ from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import DelugeConfigEntry, DelugeEntity
from . import DelugeConfigEntry
from .coordinator import DelugeDataUpdateCoordinator
from .entity import DelugeEntity
async def async_setup_entry(