mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Move control4 base entity to separate module (#126477)
* Move control4 base entity to separate module * Adjust
This commit is contained in:
parent
bed3fcfd43
commit
7b9f295071
@ -4,7 +4,6 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from aiohttp import client_exceptions
|
||||
from pyControl4.account import C4Account
|
||||
@ -23,11 +22,6 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import aiohttp_client, device_registry as dr
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
|
||||
from .const import (
|
||||
API_RETRY_TIMES,
|
||||
@ -166,41 +160,3 @@ async def get_items_of_category(hass: HomeAssistant, entry: ConfigEntry, categor
|
||||
for item in director_all_items
|
||||
if "categories" in item and category in item["categories"]
|
||||
]
|
||||
|
||||
|
||||
class Control4Entity(CoordinatorEntity[Any]):
|
||||
"""Base entity for Control4."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
entry_data: dict,
|
||||
coordinator: DataUpdateCoordinator[Any],
|
||||
name: str | None,
|
||||
idx: int,
|
||||
device_name: str | None,
|
||||
device_manufacturer: str | None,
|
||||
device_model: str | None,
|
||||
device_id: int,
|
||||
) -> None:
|
||||
"""Initialize a Control4 entity."""
|
||||
super().__init__(coordinator)
|
||||
self.entry_data = entry_data
|
||||
self._attr_name = name
|
||||
self._attr_unique_id = str(idx)
|
||||
self._idx = idx
|
||||
self._controller_unique_id = entry_data[CONF_CONTROLLER_UNIQUE_ID]
|
||||
self._device_name = device_name
|
||||
self._device_manufacturer = device_manufacturer
|
||||
self._device_model = device_model
|
||||
self._device_id = device_id
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return info of parent Control4 device of entity."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, str(self._device_id))},
|
||||
manufacturer=self._device_manufacturer,
|
||||
model=self._device_model,
|
||||
name=self._device_name,
|
||||
via_device=(DOMAIN, self._controller_unique_id),
|
||||
)
|
||||
|
51
homeassistant/components/control4/entity.py
Normal file
51
homeassistant/components/control4/entity.py
Normal file
@ -0,0 +1,51 @@
|
||||
"""The Control4 integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
|
||||
from .const import CONF_CONTROLLER_UNIQUE_ID, DOMAIN
|
||||
|
||||
|
||||
class Control4Entity(CoordinatorEntity[Any]):
|
||||
"""Base entity for Control4."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
entry_data: dict,
|
||||
coordinator: DataUpdateCoordinator[Any],
|
||||
name: str | None,
|
||||
idx: int,
|
||||
device_name: str | None,
|
||||
device_manufacturer: str | None,
|
||||
device_model: str | None,
|
||||
device_id: int,
|
||||
) -> None:
|
||||
"""Initialize a Control4 entity."""
|
||||
super().__init__(coordinator)
|
||||
self.entry_data = entry_data
|
||||
self._attr_name = name
|
||||
self._attr_unique_id = str(idx)
|
||||
self._idx = idx
|
||||
self._controller_unique_id = entry_data[CONF_CONTROLLER_UNIQUE_ID]
|
||||
self._device_name = device_name
|
||||
self._device_manufacturer = device_manufacturer
|
||||
self._device_model = device_model
|
||||
self._device_id = device_id
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return info of parent Control4 device of entity."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, str(self._device_id))},
|
||||
manufacturer=self._device_manufacturer,
|
||||
model=self._device_model,
|
||||
name=self._device_name,
|
||||
via_device=(DOMAIN, self._controller_unique_id),
|
||||
)
|
@ -23,9 +23,10 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from . import Control4Entity, get_items_of_category
|
||||
from . import get_items_of_category
|
||||
from .const import CONF_DIRECTOR, CONTROL4_ENTITY_TYPE, DOMAIN
|
||||
from .director_utils import update_variables_for_config_entry
|
||||
from .entity import Control4Entity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -24,9 +24,9 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from . import Control4Entity
|
||||
from .const import CONF_DIRECTOR, CONF_DIRECTOR_ALL_ITEMS, CONF_UI_CONFIGURATION, DOMAIN
|
||||
from .director_utils import update_variables_for_config_entry
|
||||
from .entity import Control4Entity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user