Use DeviceInfo object d-o (#96280)

pull/96317/head
Joost Lekkerkerker 2023-07-11 19:41:55 +02:00 committed by GitHub
parent 2f6826dbe3
commit a04aaf10a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 43 deletions

View File

@ -5,6 +5,7 @@ from homeassistant.components import persistent_notification
from homeassistant.components.button import ButtonEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import DOMAIN
@ -43,10 +44,10 @@ class DemoButton(ButtonEntity):
"""Initialize the Demo button entity."""
self._attr_unique_id = unique_id
self._attr_icon = icon
self._attr_device_info = {
"identifiers": {(DOMAIN, unique_id)},
"name": device_name,
}
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, unique_id)},
name=device_name,
)
async def async_press(self) -> None:
"""Send out a persistent notification."""

View File

@ -14,6 +14,7 @@ from homeassistant.components.climate import (
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import DOMAIN
@ -152,10 +153,10 @@ class DemoClimate(ClimateEntity):
self._swing_modes = ["auto", "1", "2", "3", "off"]
self._target_temperature_high = target_temp_high
self._target_temperature_low = target_temp_low
self._attr_device_info = {
"identifiers": {(DOMAIN, unique_id)},
"name": device_name,
}
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, unique_id)},
name=device_name,
)
@property
def unique_id(self) -> str:

View File

@ -21,6 +21,7 @@ from elmax_api.model.panel import PanelEntry, PanelStatus
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, HomeAssistantError
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
@ -168,17 +169,17 @@ class ElmaxEntity(CoordinatorEntity[ElmaxCoordinator]):
return self._device.name
@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Return device specific attributes."""
return {
"identifiers": {(DOMAIN, self._panel.hash)},
"name": self._panel.get_name_by_user(
return DeviceInfo(
identifiers={(DOMAIN, self._panel.hash)},
name=self._panel.get_name_by_user(
self.coordinator.http_client.get_authenticated_username()
),
"manufacturer": "Elmax",
"model": self._panel_version,
"sw_version": self._panel_version,
}
manufacturer="Elmax",
model=self._panel_version,
sw_version=self._panel_version,
)
@property
def available(self) -> bool:

View File

@ -5,6 +5,7 @@ import urllib.parse
from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
@ -38,12 +39,12 @@ class KMtronicSwitch(CoordinatorEntity, SwitchEntity):
self._reverse = reverse
hostname = urllib.parse.urlsplit(hub.host).hostname
self._attr_device_info = {
"identifiers": {(DOMAIN, config_entry_id)},
"name": f"Controller {hostname}",
"manufacturer": MANUFACTURER,
"configuration_url": hub.host,
}
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, config_entry_id)},
name=f"Controller {hostname}",
manufacturer=MANUFACTURER,
configuration_url=hub.host,
)
self._attr_name = f"Relay{relay.id}"
self._attr_unique_id = f"{config_entry_id}_relay{relay.id}"

View File

@ -276,16 +276,16 @@ class LcnEntity(Entity):
f" ({get_device_model(self.config[CONF_DOMAIN], self.config[CONF_DOMAIN_DATA])})"
)
return {
"identifiers": {(DOMAIN, self.unique_id)},
"name": f"{address}.{self.config[CONF_RESOURCE]}",
"model": model,
"manufacturer": "Issendorff",
"via_device": (
return DeviceInfo(
identifiers={(DOMAIN, self.unique_id)},
name=f"{address}.{self.config[CONF_RESOURCE]}",
model=model,
manufacturer="Issendorff",
via_device=(
DOMAIN,
generate_unique_id(self.entry_id, self.config[CONF_ADDRESS]),
),
}
)
async def async_added_to_hass(self) -> None:
"""Run when entity about to be added to hass."""

View File

@ -219,14 +219,14 @@ def _async_register_bridge_device(
"""Register the bridge device in the device registry."""
device_registry = dr.async_get(hass)
device_args: DeviceInfo = {
"name": bridge_device["name"],
"manufacturer": MANUFACTURER,
"identifiers": {(DOMAIN, bridge_device["serial"])},
"model": f"{bridge_device['model']} ({bridge_device['type']})",
"via_device": (DOMAIN, bridge_device["serial"]),
"configuration_url": "https://device-login.lutron.com",
}
device_args = DeviceInfo(
name=bridge_device["name"],
manufacturer=MANUFACTURER,
identifiers={(DOMAIN, bridge_device["serial"])},
model=f"{bridge_device['model']} ({bridge_device['type']})",
via_device=(DOMAIN, bridge_device["serial"]),
configuration_url="https://device-login.lutron.com",
)
area = _area_name_from_id(bridge.areas, bridge_device["area"])
if area != UNASSIGNED_AREA:

View File

@ -60,9 +60,9 @@ class OverkizEntity(CoordinatorEntity[OverkizDataUpdateCoordinator]):
if self.is_sub_device:
# Only return the url of the base device, to inherit device name
# and model from parent device.
return {
"identifiers": {(DOMAIN, self.executor.base_device_url)},
}
return DeviceInfo(
identifiers={(DOMAIN, self.executor.base_device_url)},
)
manufacturer = (
self.executor.select_attribute(OverkizAttribute.CORE_MANUFACTURER)

View File

@ -527,6 +527,6 @@ class OverkizHomeKitSetupCodeSensor(OverkizEntity, SensorEntity):
# By default this sensor will be listed at a virtual HomekitStack device,
# but it makes more sense to show this at the gateway device
# in the entity registry.
return {
"identifiers": {(DOMAIN, self.executor.get_gateway_id())},
}
return DeviceInfo(
identifiers={(DOMAIN, self.executor.get_gateway_id())},
)