mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Adapt bond to set via_device_id in DeviceInfo (#178156)
This commit is contained in:
@@ -4,7 +4,7 @@ from abc import abstractmethod
|
||||
from asyncio import Lock
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from typing import override
|
||||
from typing import TYPE_CHECKING, override
|
||||
|
||||
from aiohttp import ClientError
|
||||
|
||||
@@ -14,9 +14,9 @@ from homeassistant.const import (
|
||||
ATTR_NAME,
|
||||
ATTR_SUGGESTED_AREA,
|
||||
ATTR_SW_VERSION,
|
||||
ATTR_VIA_DEVICE,
|
||||
)
|
||||
from homeassistant.core import CALLBACK_TYPE, HassJob, callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.event import async_call_later
|
||||
@@ -86,7 +86,14 @@ class BondEntity(Entity):
|
||||
if self.name is not None:
|
||||
device_info[ATTR_NAME] = self._device.name
|
||||
if self._hub.bond_id is not None:
|
||||
device_info[ATTR_VIA_DEVICE] = (DOMAIN, self._hub.bond_id)
|
||||
config_entry = self.platform.config_entry
|
||||
if TYPE_CHECKING:
|
||||
assert config_entry
|
||||
device_info["via_device_id"] = dr.async_get_device_id_by_identifier(
|
||||
self.hass,
|
||||
(DOMAIN, self._hub.bond_id),
|
||||
config_entry_id=config_entry.entry_id,
|
||||
)
|
||||
if self._device.location is not None:
|
||||
device_info[ATTR_SUGGESTED_AREA] = self._device.location
|
||||
if not self._hub.is_bridge:
|
||||
|
||||
@@ -205,6 +205,31 @@ async def test_old_identifiers_are_removed(
|
||||
assert device_registry.async_get_device(identifiers={new_identifiers}) is not None
|
||||
|
||||
|
||||
async def test_device_via_device_links(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
) -> None:
|
||||
"""Test that child devices link to the hub via via_device_id."""
|
||||
config_entry = await setup_platform(
|
||||
hass,
|
||||
FAN_DOMAIN,
|
||||
ceiling_fan("name-1"),
|
||||
bond_version={"bondid": "test-hub-id"},
|
||||
bond_device_id="test-device-id",
|
||||
)
|
||||
|
||||
hub_device = device_registry.async_get_device_by_identifier(
|
||||
(DOMAIN, "test-hub-id"), config_entry.entry_id
|
||||
)
|
||||
assert hub_device is not None
|
||||
|
||||
entity = entity_registry.entities["fan.name_1"]
|
||||
child_device = device_registry.async_get(entity.device_id)
|
||||
assert child_device is not None
|
||||
assert child_device.via_device_id == hub_device.id
|
||||
|
||||
|
||||
async def test_smart_by_bond_device_suggested_area(
|
||||
hass: HomeAssistant,
|
||||
area_registry: ar.AreaRegistry,
|
||||
|
||||
Reference in New Issue
Block a user