mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Use DeviceInfo on components with via_device (A-G) (#58210)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
5c3d2a5071
commit
8dfa628af0
@ -77,11 +77,11 @@ class AcmedaBase(entity.Entity):
|
||||
return self.roller.name
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> entity.DeviceInfo:
|
||||
"""Return the device info."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.unique_id)},
|
||||
"name": self.roller.name,
|
||||
"manufacturer": "Rollease Acmeda",
|
||||
"via_device": (DOMAIN, self.roller.hub.id),
|
||||
}
|
||||
return entity.DeviceInfo(
|
||||
identifiers={(DOMAIN, self.unique_id)},
|
||||
name=self.roller.name,
|
||||
manufacturer="Rollease Acmeda",
|
||||
via_device=(DOMAIN, self.roller.hub.id),
|
||||
)
|
||||
|
@ -2,7 +2,7 @@
|
||||
from boschshcpy.device import SHCDevice
|
||||
|
||||
from homeassistant.helpers.device_registry import async_get as get_dev_reg
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
@ -28,18 +28,18 @@ class SHCEntity(Entity):
|
||||
self._entry_id = entry_id
|
||||
self._attr_name = device.name
|
||||
self._attr_unique_id = device.serial
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, device.id)},
|
||||
"name": device.name,
|
||||
"manufacturer": device.manufacturer,
|
||||
"model": device.device_model,
|
||||
"via_device": (
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device.id)},
|
||||
name=device.name,
|
||||
manufacturer=device.manufacturer,
|
||||
model=device.device_model,
|
||||
via_device=(
|
||||
DOMAIN,
|
||||
device.parent_device_id
|
||||
if device.parent_device_id is not None
|
||||
else parent_id,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to SHC events."""
|
||||
|
@ -1,9 +1,10 @@
|
||||
"""Base class for deCONZ devices."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.device_registry import CONNECTION_ZIGBEE
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import DOMAIN as DECONZ_DOMAIN
|
||||
|
||||
@ -30,20 +31,20 @@ class DeconzBase:
|
||||
return self._device.unique_id.split("-", 1)[0]
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo | None:
|
||||
"""Return a device description for device registry."""
|
||||
if self.serial is None:
|
||||
return None
|
||||
|
||||
return {
|
||||
"connections": {(CONNECTION_ZIGBEE, self.serial)},
|
||||
"identifiers": {(DECONZ_DOMAIN, self.serial)},
|
||||
"manufacturer": self._device.manufacturer,
|
||||
"model": self._device.model_id,
|
||||
"name": self._device.name,
|
||||
"sw_version": self._device.software_version,
|
||||
"via_device": (DECONZ_DOMAIN, self.gateway.api.config.bridge_id),
|
||||
}
|
||||
return DeviceInfo(
|
||||
connections={(CONNECTION_ZIGBEE, self.serial)},
|
||||
identifiers={(DECONZ_DOMAIN, self.serial)},
|
||||
manufacturer=self._device.manufacturer,
|
||||
model=self._device.model_id,
|
||||
name=self._device.name,
|
||||
sw_version=self._device.software_version,
|
||||
via_device=(DECONZ_DOMAIN, self.gateway.api.config.bridge_id),
|
||||
)
|
||||
|
||||
|
||||
class DeconzDevice(DeconzBase, Entity):
|
||||
|
@ -35,6 +35,7 @@ from homeassistant.components.light import (
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.util.color import color_hs_to_xy
|
||||
|
||||
from .const import DOMAIN as DECONZ_DOMAIN, POWER_PLUGS
|
||||
@ -266,15 +267,15 @@ class DeconzGroup(DeconzBaseLight):
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return a device description for device registry."""
|
||||
return {
|
||||
"identifiers": {(DECONZ_DOMAIN, self.unique_id)},
|
||||
"manufacturer": "Dresden Elektronik",
|
||||
"model": "deCONZ group",
|
||||
"name": self._device.name,
|
||||
"via_device": (DECONZ_DOMAIN, self.gateway.api.config.bridge_id),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DECONZ_DOMAIN, self.unique_id)},
|
||||
manufacturer="Dresden Elektronik",
|
||||
model="deCONZ group",
|
||||
name=self._device.name,
|
||||
via_device=(DECONZ_DOMAIN, self.gateway.api.config.bridge_id),
|
||||
)
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
|
@ -1,6 +1,4 @@
|
||||
"""Constants for the DirecTV integration."""
|
||||
from typing import Final
|
||||
|
||||
DOMAIN = "directv"
|
||||
|
||||
# Attributes
|
||||
@ -8,7 +6,6 @@ ATTR_MEDIA_CURRENTLY_RECORDING = "media_currently_recording"
|
||||
ATTR_MEDIA_RATING = "media_rating"
|
||||
ATTR_MEDIA_RECORDED = "media_recorded"
|
||||
ATTR_MEDIA_START_TIME = "media_start_time"
|
||||
ATTR_VIA_DEVICE: Final = "via_device"
|
||||
|
||||
CONF_RECEIVER_ID = "receiver_id"
|
||||
|
||||
|
@ -3,16 +3,9 @@ from __future__ import annotations
|
||||
|
||||
from directv import DIRECTV
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_IDENTIFIERS,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_NAME,
|
||||
ATTR_SW_VERSION,
|
||||
)
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import ATTR_VIA_DEVICE, DOMAIN
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
class DIRECTVEntity(Entity):
|
||||
@ -28,11 +21,11 @@ class DIRECTVEntity(Entity):
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information about this DirecTV receiver."""
|
||||
return {
|
||||
ATTR_IDENTIFIERS: {(DOMAIN, self._device_id)},
|
||||
ATTR_NAME: self.name,
|
||||
ATTR_MANUFACTURER: self.dtv.device.info.brand,
|
||||
ATTR_MODEL: None,
|
||||
ATTR_SW_VERSION: self.dtv.device.info.version,
|
||||
ATTR_VIA_DEVICE: (DOMAIN, self.dtv.device.info.receiver_id),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._device_id)},
|
||||
name=self.name,
|
||||
manufacturer=self.dtv.device.info.brand,
|
||||
model=None,
|
||||
sw_version=self.dtv.device.info.version,
|
||||
via_device=(DOMAIN, self.dtv.device.info.receiver_id),
|
||||
)
|
||||
|
@ -26,7 +26,7 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
@ -452,11 +452,11 @@ class ElkEntity(Entity):
|
||||
self._element_callback(self._element, {})
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Device info connecting via the ElkM1 system."""
|
||||
return {
|
||||
"via_device": (DOMAIN, f"{self._prefix}_system"),
|
||||
}
|
||||
return DeviceInfo(
|
||||
via_device=(DOMAIN, f"{self._prefix}_system"),
|
||||
)
|
||||
|
||||
|
||||
class ElkAttachedEntity(ElkEntity):
|
||||
|
@ -163,16 +163,16 @@ class FreeboxDiskSensor(FreeboxSensor):
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device information."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._disk["id"])},
|
||||
"name": f"Disk {self._disk['id']}",
|
||||
"model": self._disk["model"],
|
||||
"sw_version": self._disk["firmware"],
|
||||
"via_device": (
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._disk["id"])},
|
||||
name=f"Disk {self._disk['id']}",
|
||||
model=self._disk["model"],
|
||||
sw_version=self._disk["firmware"],
|
||||
via_device=(
|
||||
DOMAIN,
|
||||
self._router.mac,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_update_state(self) -> None:
|
||||
|
@ -351,17 +351,17 @@ class FritzDeviceBase(Entity):
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device information."""
|
||||
return {
|
||||
"connections": {(CONNECTION_NETWORK_MAC, self._mac)},
|
||||
"identifiers": {(DOMAIN, self._mac)},
|
||||
"default_name": self.name,
|
||||
"default_manufacturer": "AVM",
|
||||
"default_model": "FRITZ!Box Tracked device",
|
||||
"via_device": (
|
||||
return DeviceInfo(
|
||||
connections={(CONNECTION_NETWORK_MAC, self._mac)},
|
||||
identifiers={(DOMAIN, self._mac)},
|
||||
default_name=self.name,
|
||||
default_manufacturer="AVM",
|
||||
default_model="FRITZ!Box Tracked device",
|
||||
via_device=(
|
||||
DOMAIN,
|
||||
self._router.unique_id,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
|
@ -11,7 +11,7 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_IP_ADDRESS, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.entity import EntityDescription
|
||||
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
@ -244,11 +244,11 @@ class PairedSensorEntity(GuardianEntity):
|
||||
super().__init__(entry, description)
|
||||
|
||||
paired_sensor_uid = coordinator.data["uid"]
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, paired_sensor_uid)},
|
||||
"name": f"Guardian Paired Sensor {paired_sensor_uid}",
|
||||
"via_device": (DOMAIN, entry.data[CONF_UID]),
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, paired_sensor_uid)},
|
||||
name=f"Guardian Paired Sensor {paired_sensor_uid}",
|
||||
via_device=(DOMAIN, entry.data[CONF_UID]),
|
||||
)
|
||||
self._attr_name = (
|
||||
f"Guardian Paired Sensor {paired_sensor_uid}: {description.name}"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user