mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Move deluge base entity to separate module (#126479)
This commit is contained in:
parent
7b9f295071
commit
432d44c20d
@ -17,10 +17,8 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
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
|
from .coordinator import DelugeDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS = [Platform.SENSOR, Platform.SWITCH]
|
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:
|
async def async_unload_entry(hass: HomeAssistant, entry: DelugeConfigEntry) -> 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 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,
|
|
||||||
)
|
|
||||||
|
30
homeassistant/components/deluge/entity.py
Normal file
30
homeassistant/components/deluge/entity.py
Normal 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,
|
||||||
|
)
|
@ -17,9 +17,10 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
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 .const import CURRENT_STATUS, DATA_KEYS, DOWNLOAD_SPEED, UPLOAD_SPEED
|
||||||
from .coordinator import DelugeDataUpdateCoordinator
|
from .coordinator import DelugeDataUpdateCoordinator
|
||||||
|
from .entity import DelugeEntity
|
||||||
|
|
||||||
|
|
||||||
def get_state(data: dict[str, float], key: str) -> str | float:
|
def get_state(data: dict[str, float], key: str) -> str | float:
|
||||||
|
@ -9,8 +9,9 @@ from homeassistant.const import Platform
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import DelugeConfigEntry, DelugeEntity
|
from . import DelugeConfigEntry
|
||||||
from .coordinator import DelugeDataUpdateCoordinator
|
from .coordinator import DelugeDataUpdateCoordinator
|
||||||
|
from .entity import DelugeEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user