Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ZHA "referencing a non existing via_device" warning #135008

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/zha/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=zha_device_info[ATTR_MANUFACTURER],
model=zha_device_info[ATTR_MODEL],
name=zha_device_info[ATTR_NAME],
via_device=(DOMAIN, zha_gateway.state.node_info.ieee),
via_device=(DOMAIN, str(zha_gateway.state.node_info.ieee)),
)

@callback
Expand Down
47 changes: 47 additions & 0 deletions tests/components/zha/test_entity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Test ZHA entities."""

from zigpy.profiles import zha
from zigpy.zcl.clusters import general

from homeassistant.components.zha.helpers import get_zha_gateway
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr

from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE


async def test_device_registry_via_device(
hass: HomeAssistant,
setup_zha,
zigpy_device_mock,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test ZHA `via_device` is set correctly."""

await setup_zha()
gateway = get_zha_gateway(hass)

zigpy_device = zigpy_device_mock(
{
1: {
SIG_EP_INPUT: [general.Basic.cluster_id],
SIG_EP_OUTPUT: [],
SIG_EP_TYPE: zha.DeviceType.ON_OFF_SWITCH,
SIG_EP_PROFILE: zha.PROFILE_ID,
}
},
)

zha_device = gateway.get_or_create_device(zigpy_device)
await gateway.async_device_initialized(zigpy_device)
await hass.async_block_till_done(wait_background_tasks=True)

reg_coordinator_device = device_registry.async_get_device(
identifiers={("zha", str(gateway.state.node_info.ieee))}
)

reg_device = device_registry.async_get_device(
identifiers={("zha", str(zha_device.ieee))}
)

assert reg_device.via_device_id == reg_coordinator_device.id
Loading