Use DeviceInfo in control4 (#58388)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/58405/head
epenet 2021-10-25 12:23:11 +02:00 committed by GitHub
parent e5e38ace6c
commit 9d952d0242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 25 deletions

View File

@ -20,6 +20,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import aiohttp_client, device_registry as dr from homeassistant.helpers import aiohttp_client, device_registry as dr
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import ( from homeassistant.helpers.update_coordinator import (
CoordinatorEntity, CoordinatorEntity,
DataUpdateCoordinator, DataUpdateCoordinator,
@ -147,7 +148,6 @@ class Control4Entity(CoordinatorEntity):
def __init__( def __init__(
self, self,
entry_data: dict, entry_data: dict,
entry: ConfigEntry,
coordinator: DataUpdateCoordinator, coordinator: DataUpdateCoordinator,
name: str, name: str,
idx: int, idx: int,
@ -158,9 +158,9 @@ class Control4Entity(CoordinatorEntity):
) -> None: ) -> None:
"""Initialize a Control4 entity.""" """Initialize a Control4 entity."""
super().__init__(coordinator) super().__init__(coordinator)
self.entry = entry
self.entry_data = entry_data self.entry_data = entry_data
self._name = name self._attr_name = name
self._attr_unique_id = str(idx)
self._idx = idx self._idx = idx
self._controller_unique_id = entry_data[CONF_CONTROLLER_UNIQUE_ID] self._controller_unique_id = entry_data[CONF_CONTROLLER_UNIQUE_ID]
self._device_name = device_name self._device_name = device_name
@ -169,23 +169,12 @@ class Control4Entity(CoordinatorEntity):
self._device_id = device_id self._device_id = device_id
@property @property
def name(self): def device_info(self) -> DeviceInfo:
"""Return name of entity."""
return self._name
@property
def unique_id(self) -> str:
"""Return a unique ID."""
return str(self._idx)
@property
def device_info(self):
"""Return info of parent Control4 device of entity.""" """Return info of parent Control4 device of entity."""
return { return DeviceInfo(
"config_entry_id": self.entry.entry_id, identifiers={(DOMAIN, str(self._device_id))},
"identifiers": {(DOMAIN, self._device_id)}, manufacturer=self._device_manufacturer,
"name": self._device_name, model=self._device_model,
"manufacturer": self._device_manufacturer, name=self._device_name,
"model": self._device_model, via_device=(DOMAIN, self._controller_unique_id),
"via_device": (DOMAIN, self._controller_unique_id), )
}

View File

@ -122,7 +122,6 @@ async def async_setup_entry(
entity_list.append( entity_list.append(
Control4Light( Control4Light(
entry_data, entry_data,
entry,
item_coordinator, item_coordinator,
item_name, item_name,
item_id, item_id,
@ -143,7 +142,6 @@ class Control4Light(Control4Entity, LightEntity):
def __init__( def __init__(
self, self,
entry_data: dict, entry_data: dict,
entry: ConfigEntry,
coordinator: DataUpdateCoordinator, coordinator: DataUpdateCoordinator,
name: str, name: str,
idx: int, idx: int,
@ -156,7 +154,6 @@ class Control4Light(Control4Entity, LightEntity):
"""Initialize Control4 light entity.""" """Initialize Control4 light entity."""
super().__init__( super().__init__(
entry_data, entry_data,
entry,
coordinator, coordinator,
name, name,
idx, idx,