Adapt withings to set via_device_id in DeviceInfo (#177851)

This commit is contained in:
Erik Montnemery
2026-08-03 17:36:40 +02:00
committed by GitHub
parent 34aa09fb2f
commit d3d79d843c
2 changed files with 29 additions and 1 deletions
+6 -1
View File
@@ -4,6 +4,7 @@ from typing import Any, override
from aiowithings import Device
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
@@ -50,7 +51,11 @@ class WithingsDeviceEntity(WithingsEntity[WithingsDeviceDataUpdateCoordinator]):
manufacturer="Withings",
name=self.device.raw_model,
model=self.device.raw_model,
via_device=(DOMAIN, str(coordinator.config_entry.unique_id)),
via_device_id=dr.async_get_device_id_by_identifier(
coordinator.hass,
(DOMAIN, str(coordinator.config_entry.unique_id)),
config_entry_id=coordinator.config_entry.entry_id,
),
)
@property
+23
View File
@@ -715,6 +715,29 @@ async def test_devices(
assert device == snapshot(name=device_id)
@pytest.mark.usefixtures("withings")
async def test_device_via_device_id(
hass: HomeAssistant,
webhook_config_entry: MockConfigEntry,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test the physical device is linked to the account device via via_device_id."""
await setup_integration(hass, webhook_config_entry)
await hass.async_block_till_done()
account_device = device_registry.async_get_device_by_identifier(
(DOMAIN, str(webhook_config_entry.unique_id)), webhook_config_entry.entry_id
)
assert account_device is not None
device = device_registry.async_get_device_by_identifier(
(DOMAIN, "f998be4b9ccc9e136fd8cd8e8e344c31ec3b271d"),
webhook_config_entry.entry_id,
)
assert device is not None
assert device.via_device_id == account_device.id
async def test_oauth_implementation_not_available(
hass: HomeAssistant,
webhook_config_entry: MockConfigEntry,