Move nzbget base entity to separate module (#126502)

pull/126520/head
epenet 2024-09-23 12:45:13 +02:00 committed by GitHub
parent 0163f3d57e
commit 438cbc99b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 26 deletions

View File

@ -6,8 +6,6 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import (
ATTR_SPEED,
@ -93,25 +91,3 @@ def _async_register_services(
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update."""
await hass.config_entries.async_reload(entry.entry_id)
class NZBGetEntity(CoordinatorEntity[NZBGetDataUpdateCoordinator]):
"""Defines a base NZBGet entity."""
_attr_has_entity_name = True
def __init__(
self,
*,
entry_id: str,
entry_name: str,
coordinator: NZBGetDataUpdateCoordinator,
) -> None:
"""Initialize the NZBGet entity."""
super().__init__(coordinator)
self._entry_id = entry_id
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, entry_id)},
name=entry_name,
entry_type=DeviceEntryType.SERVICE,
)

View File

@ -0,0 +1,29 @@
"""The NZBGet integration."""
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .coordinator import NZBGetDataUpdateCoordinator
class NZBGetEntity(CoordinatorEntity[NZBGetDataUpdateCoordinator]):
"""Defines a base NZBGet entity."""
_attr_has_entity_name = True
def __init__(
self,
*,
entry_id: str,
entry_name: str,
coordinator: NZBGetDataUpdateCoordinator,
) -> None:
"""Initialize the NZBGet entity."""
super().__init__(coordinator)
self._entry_id = entry_id
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, entry_id)},
name=entry_name,
entry_type=DeviceEntryType.SERVICE,
)

View File

@ -17,9 +17,9 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.util.dt import utcnow
from . import NZBGetEntity
from .const import DATA_COORDINATOR, DOMAIN
from .coordinator import NZBGetDataUpdateCoordinator
from .entity import NZBGetEntity
_LOGGER = logging.getLogger(__name__)

View File

@ -10,9 +10,9 @@ from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import NZBGetEntity
from .const import DATA_COORDINATOR, DOMAIN
from .coordinator import NZBGetDataUpdateCoordinator
from .entity import NZBGetEntity
async def async_setup_entry(