mirror of
https://github.com/home-assistant/core
synced 2024-08-15 18:25:44 +02:00
Use DeviceInfo on components with via_device (R-X) (#58213)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
176ed4f7ba
commit
a3d1159a13
@ -35,6 +35,7 @@ from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
async_dispatcher_send,
|
||||
)
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.util import convert
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
@ -160,18 +161,18 @@ class RoonDevice(MediaPlayerEntity):
|
||||
return [self._server.entity_id(roon_name) for roon_name in roon_names]
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device info."""
|
||||
dev_model = "player"
|
||||
if self.player_data.get("source_controls"):
|
||||
dev_model = self.player_data["source_controls"][0].get("display_name")
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.unique_id)},
|
||||
"name": self.name,
|
||||
"manufacturer": "RoonLabs",
|
||||
"model": dev_model,
|
||||
"via_device": (DOMAIN, self._server.roon_id),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.unique_id)},
|
||||
name=self.name,
|
||||
manufacturer="RoonLabs",
|
||||
model=dev_model,
|
||||
via_device=(DOMAIN, self._server.roon_id),
|
||||
)
|
||||
|
||||
def update_data(self, player_data=None):
|
||||
"""Update session object."""
|
||||
|
@ -121,12 +121,12 @@ class RuckusUnleashedDevice(CoordinatorEntity, ScannerEntity):
|
||||
def device_info(self) -> DeviceInfo | None:
|
||||
"""Return the device information."""
|
||||
if self.is_connected:
|
||||
return {
|
||||
"name": self.name,
|
||||
"connections": {(CONNECTION_NETWORK_MAC, self._mac)},
|
||||
"via_device": (
|
||||
return DeviceInfo(
|
||||
name=self.name,
|
||||
connections={(CONNECTION_NETWORK_MAC, self._mac)},
|
||||
via_device=(
|
||||
CONNECTION_NETWORK_MAC,
|
||||
self.coordinator.data[API_CLIENTS][self._mac][API_ACCESS_POINT],
|
||||
),
|
||||
}
|
||||
)
|
||||
return None
|
||||
|
@ -125,8 +125,8 @@ class SIABaseEntity(RestoreEntity):
|
||||
"""Return the device_info."""
|
||||
assert self._attr_name is not None
|
||||
assert self.unique_id is not None
|
||||
return {
|
||||
"name": self._attr_name,
|
||||
"identifiers": {(DOMAIN, self.unique_id)},
|
||||
"via_device": (DOMAIN, f"{self._port}_{self._account}"),
|
||||
}
|
||||
return DeviceInfo(
|
||||
name=self._attr_name,
|
||||
identifiers={(DOMAIN, self.unique_id)},
|
||||
via_device=(DOMAIN, f"{self._port}_{self._account}"),
|
||||
)
|
||||
|
@ -33,6 +33,7 @@ from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
device_registry as dr,
|
||||
)
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.service import (
|
||||
async_register_admin_service,
|
||||
verify_domain_control,
|
||||
@ -442,14 +443,13 @@ class SimpliSafeEntity(CoordinatorEntity):
|
||||
serial = system.serial
|
||||
|
||||
self._attr_extra_state_attributes = {ATTR_SYSTEM_ID: system.system_id}
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, serial)},
|
||||
"manufacturer": "SimpliSafe",
|
||||
"model": model,
|
||||
"name": device_name,
|
||||
"via_device": (DOMAIN, system.system_id),
|
||||
}
|
||||
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, serial)},
|
||||
manufacturer="SimpliSafe",
|
||||
model=model,
|
||||
name=device_name,
|
||||
via_device=(DOMAIN, system.system_id),
|
||||
)
|
||||
self._attr_name = f"{system.address} {device_name} {' '.join([w.title() for w in model.split('_')])}"
|
||||
self._attr_unique_id = serial
|
||||
self._device = device
|
||||
|
@ -3,7 +3,7 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
@ -33,19 +33,19 @@ class SomfyEntity(CoordinatorEntity, Entity):
|
||||
return self.device.name
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device specific attributes.
|
||||
|
||||
Implemented by platform classes.
|
||||
"""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.unique_id)},
|
||||
"name": self.name,
|
||||
"model": self.device.type,
|
||||
"via_device": (DOMAIN, self.device.parent_id),
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.unique_id)},
|
||||
name=self.name,
|
||||
model=self.device.type,
|
||||
via_device=(DOMAIN, self.device.parent_id),
|
||||
# For the moment, Somfy only returns their own device.
|
||||
"manufacturer": "Somfy",
|
||||
}
|
||||
manufacturer="Somfy",
|
||||
)
|
||||
|
||||
def has_capability(self, capability: str) -> bool:
|
||||
"""Test if device has a capability."""
|
||||
|
@ -89,20 +89,20 @@ class SynoDSMCamera(SynologyDSMBaseEntity, Camera):
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device information."""
|
||||
return {
|
||||
"identifiers": {
|
||||
return DeviceInfo(
|
||||
identifiers={
|
||||
(
|
||||
DOMAIN,
|
||||
f"{self._api.information.serial}_{self.camera_data.id}",
|
||||
)
|
||||
},
|
||||
"name": self.camera_data.name,
|
||||
"model": self.camera_data.model,
|
||||
"via_device": (
|
||||
name=self.camera_data.name,
|
||||
model=self.camera_data.model,
|
||||
via_device=(
|
||||
DOMAIN,
|
||||
f"{self._api.information.serial}_{SynoSurveillanceStation.INFO_API_KEY}",
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
|
@ -106,16 +106,16 @@ class SynoDSMSurveillanceHomeModeToggle(SynologyDSMBaseEntity, ToggleEntity):
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device information."""
|
||||
return {
|
||||
"identifiers": {
|
||||
return DeviceInfo(
|
||||
identifiers={
|
||||
(
|
||||
DOMAIN,
|
||||
f"{self._api.information.serial}_{SynoSurveillanceStation.INFO_API_KEY}",
|
||||
)
|
||||
},
|
||||
"name": "Surveillance Station",
|
||||
"manufacturer": "Synology",
|
||||
"model": self._api.information.model,
|
||||
"sw_version": self._version,
|
||||
"via_device": (DOMAIN, self._api.information.serial),
|
||||
}
|
||||
name="Surveillance Station",
|
||||
manufacturer="Synology",
|
||||
model=self._api.information.model,
|
||||
sw_version=self._version,
|
||||
via_device=(DOMAIN, self._api.information.serial),
|
||||
)
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""Base class for Tado entity."""
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import DEFAULT_NAME, DOMAIN, TADO_HOME, TADO_ZONE
|
||||
|
||||
@ -15,16 +15,16 @@ class TadoDeviceEntity(Entity):
|
||||
self.device_id = device_info["shortSerialNo"]
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device_info of the device."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.device_id)},
|
||||
"name": self.device_name,
|
||||
"manufacturer": DEFAULT_NAME,
|
||||
"sw_version": self._device_info["currentFwVersion"],
|
||||
"model": self._device_info["deviceType"],
|
||||
"via_device": (DOMAIN, self._device_info["serialNo"]),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device_id)},
|
||||
name=self.device_name,
|
||||
manufacturer=DEFAULT_NAME,
|
||||
sw_version=self._device_info["currentFwVersion"],
|
||||
model=self._device_info["deviceType"],
|
||||
via_device=(DOMAIN, self._device_info["serialNo"]),
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
@ -41,11 +41,11 @@ class ToonElectricityMeterDeviceEntity(ToonEntity):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information about this entity."""
|
||||
agreement_id = self.coordinator.data.agreement.agreement_id
|
||||
return {
|
||||
"name": "Electricity Meter",
|
||||
"identifiers": {(DOMAIN, agreement_id, "electricity")},
|
||||
"via_device": (DOMAIN, agreement_id, "meter_adapter"),
|
||||
}
|
||||
return DeviceInfo(
|
||||
name="Electricity Meter",
|
||||
identifiers={(DOMAIN, agreement_id, "electricity")},
|
||||
via_device=(DOMAIN, agreement_id, "meter_adapter"),
|
||||
)
|
||||
|
||||
|
||||
class ToonGasMeterDeviceEntity(ToonEntity):
|
||||
@ -55,11 +55,11 @@ class ToonGasMeterDeviceEntity(ToonEntity):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information about this entity."""
|
||||
agreement_id = self.coordinator.data.agreement.agreement_id
|
||||
return {
|
||||
"name": "Gas Meter",
|
||||
"identifiers": {(DOMAIN, agreement_id, "gas")},
|
||||
"via_device": (DOMAIN, agreement_id, "electricity"),
|
||||
}
|
||||
return DeviceInfo(
|
||||
name="Gas Meter",
|
||||
identifiers={(DOMAIN, agreement_id, "gas")},
|
||||
via_device=(DOMAIN, agreement_id, "electricity"),
|
||||
)
|
||||
|
||||
|
||||
class ToonWaterMeterDeviceEntity(ToonEntity):
|
||||
@ -69,11 +69,11 @@ class ToonWaterMeterDeviceEntity(ToonEntity):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information about this entity."""
|
||||
agreement_id = self.coordinator.data.agreement.agreement_id
|
||||
return {
|
||||
"name": "Water Meter",
|
||||
"identifiers": {(DOMAIN, agreement_id, "water")},
|
||||
"via_device": (DOMAIN, agreement_id, "electricity"),
|
||||
}
|
||||
return DeviceInfo(
|
||||
name="Water Meter",
|
||||
identifiers={(DOMAIN, agreement_id, "water")},
|
||||
via_device=(DOMAIN, agreement_id, "electricity"),
|
||||
)
|
||||
|
||||
|
||||
class ToonSolarDeviceEntity(ToonEntity):
|
||||
@ -83,11 +83,11 @@ class ToonSolarDeviceEntity(ToonEntity):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information about this entity."""
|
||||
agreement_id = self.coordinator.data.agreement.agreement_id
|
||||
return {
|
||||
"name": "Solar Panels",
|
||||
"identifiers": {(DOMAIN, agreement_id, "solar")},
|
||||
"via_device": (DOMAIN, agreement_id, "meter_adapter"),
|
||||
}
|
||||
return DeviceInfo(
|
||||
name="Solar Panels",
|
||||
identifiers={(DOMAIN, agreement_id, "solar")},
|
||||
via_device=(DOMAIN, agreement_id, "meter_adapter"),
|
||||
)
|
||||
|
||||
|
||||
class ToonBoilerModuleDeviceEntity(ToonEntity):
|
||||
@ -97,12 +97,12 @@ class ToonBoilerModuleDeviceEntity(ToonEntity):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information about this entity."""
|
||||
agreement_id = self.coordinator.data.agreement.agreement_id
|
||||
return {
|
||||
"name": "Boiler Module",
|
||||
"manufacturer": "Eneco",
|
||||
"identifiers": {(DOMAIN, agreement_id, "boiler_module")},
|
||||
"via_device": (DOMAIN, agreement_id),
|
||||
}
|
||||
return DeviceInfo(
|
||||
name="Boiler Module",
|
||||
manufacturer="Eneco",
|
||||
identifiers={(DOMAIN, agreement_id, "boiler_module")},
|
||||
via_device=(DOMAIN, agreement_id),
|
||||
)
|
||||
|
||||
|
||||
class ToonBoilerDeviceEntity(ToonEntity):
|
||||
@ -112,11 +112,11 @@ class ToonBoilerDeviceEntity(ToonEntity):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information about this entity."""
|
||||
agreement_id = self.coordinator.data.agreement.agreement_id
|
||||
return {
|
||||
"name": "Boiler",
|
||||
"identifiers": {(DOMAIN, agreement_id, "boiler")},
|
||||
"via_device": (DOMAIN, agreement_id, "boiler_module"),
|
||||
}
|
||||
return DeviceInfo(
|
||||
name="Boiler",
|
||||
identifiers={(DOMAIN, agreement_id, "boiler")},
|
||||
via_device=(DOMAIN, agreement_id, "boiler_module"),
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -3,7 +3,7 @@
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .parent_device import WiLightParent
|
||||
|
||||
@ -78,16 +78,16 @@ class WiLightDevice(Entity):
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device info."""
|
||||
return {
|
||||
"name": self._name,
|
||||
"identifiers": {(DOMAIN, self._unique_id)},
|
||||
"model": self._model,
|
||||
"manufacturer": "WiLight",
|
||||
"sw_version": self._sw_version,
|
||||
"via_device": (DOMAIN, self._device_id),
|
||||
}
|
||||
return DeviceInfo(
|
||||
name=self._name,
|
||||
identifiers={(DOMAIN, self._unique_id)},
|
||||
model=self._model,
|
||||
manufacturer="WiLight",
|
||||
sw_version=self._sw_version,
|
||||
via_device=(DOMAIN, self._device_id),
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
|
@ -20,7 +20,7 @@ from homeassistant.core import callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.device_registry import format_mac
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
@ -276,23 +276,23 @@ class XiaomiDevice(Entity):
|
||||
return self._device_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device info of the Xiaomi Aqara device."""
|
||||
if self._is_gateway:
|
||||
device_info = {
|
||||
"identifiers": {(DOMAIN, self._device_id)},
|
||||
"model": self._model,
|
||||
}
|
||||
device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, self._device_id)},
|
||||
model=self._model,
|
||||
)
|
||||
else:
|
||||
device_info = {
|
||||
"connections": {(dr.CONNECTION_ZIGBEE, self._device_id)},
|
||||
"identifiers": {(DOMAIN, self._device_id)},
|
||||
"manufacturer": "Xiaomi Aqara",
|
||||
"model": self._model,
|
||||
"name": self._device_name,
|
||||
"sw_version": self._protocol,
|
||||
"via_device": (DOMAIN, self._gateway_id),
|
||||
}
|
||||
DeviceInfo(
|
||||
connections={(dr.CONNECTION_ZIGBEE, self._device_id)},
|
||||
identifiers={(DOMAIN, self._device_id)},
|
||||
manufacturer="Xiaomi Aqara",
|
||||
model=self._model,
|
||||
name=self._device_name,
|
||||
sw_version=self._protocol,
|
||||
via_device=(DOMAIN, self._gateway_id),
|
||||
)
|
||||
|
||||
return device_info
|
||||
|
||||
|
@ -7,7 +7,7 @@ from micloud.micloudexception import MiCloudAccessDenied
|
||||
from miio import DeviceException, gateway
|
||||
from miio.gateway.gateway import GATEWAY_MODEL_EU
|
||||
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
@ -151,16 +151,16 @@ class XiaomiGatewayDevice(CoordinatorEntity, Entity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device info of the gateway."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._sub_device.sid)},
|
||||
"via_device": (DOMAIN, self._entry.unique_id),
|
||||
"manufacturer": "Xiaomi",
|
||||
"name": self._sub_device.name,
|
||||
"model": self._sub_device.model,
|
||||
"sw_version": self._sub_device.firmware_version,
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._sub_device.sid)},
|
||||
via_device=(DOMAIN, self._entry.unique_id),
|
||||
manufacturer="Xiaomi",
|
||||
name=self._sub_device.name,
|
||||
model=self._sub_device.model,
|
||||
sw_version=self._sub_device.firmware_version,
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
|
Loading…
Reference in New Issue
Block a user