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