INNER CODE UNIT · Python
_apply_device_link
3dg1luk43/ha_washdata · custom_components/ha_washdata/__init__.py:1326
def _apply_device_link(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Sync the WashData device's via_device link with the configured option.
When CONF_LINKED_DEVICE points at an existing device (e.g. the smart plug or
appliance), the WashData device is shown as "Connected via <device>" in the
HA device registry. Clearing the option removes the link. Stale targets that
no longer exist - and a target that is this entry's own WashData device, which
HA rejects as a self-reference (#418) - are treated as "no link" so the
registry never references a deleted device or itself.
"""
_log = DeviceLoggerAdapter(_LOGGER, entry.title)
registry = dr.async_get(hass)
identifier = (DOMAIN, entry.entry_id)
if hasattr(registry, "async_get_device_by_identifier"):
# HA 2026.9+ deprecated async_get_device because identifiers are no longer
# unique across config entries (issue #405). Our device's identifier is
# owned by this entry, so the by-identifier lookup is unambiguous. The
# attribute guard keeps us working on the older HA the manifest still