Skip to content

fix(entity): replace deprecated via_device with via_device_id - #9

Merged
C3H3-AI merged 3 commits into
mainfrom
fix/deprecated-via-device
Sep 13, 2026
Merged

C3H3-AI merged 3 commits into
mainfrom
fix/deprecated-via-device

Conversation

@C3H3-AI

@C3H3-AI C3H3-AI commented Sep 13, 2026

Copy link
Copy Markdown
Owner

Problem

Home Assistant logs a deprecation warning on every setup:

WARNING (MainThread) [homeassistant.helpers.frame] Detected that custom
integration 'hotata' calls `device_registry.async_get_or_create` with a
deprecated `via_device` parameter; use `via_device_id` instead at
custom_components/hotata/entity.py, line 74
This will stop working in Home Assistant 2027.8.0

DeviceInfo.via_device takes an identifier tuple, which the device registry
no longer accepts. The parameter is removed in HA 2027.8, so on that release
the gateway relationship silently disappears.

Why this is not a one-line swap

via_device_id needs the device registry id of the gateway, and that id
does not exist when __init__ builds DeviceInfo: entities are constructed
before the registry has finished processing, and the gateway device may not be
registered yet. Passing an id that early would leave the relationship
permanently unset.

Fix

Move the link into async_added_to_hass, which runs after both the entity's
own device and its gateway are registered:

async def async_added_to_hass(self) -> None:
    await super().async_added_to_hass()

    parent_iot_id = self.device.parent_iot_id
    if not parent_iot_id:
        return

    registry = dr.async_get(self.hass)

    parent = registry.async_get_device(identifiers={(DOMAIN, parent_iot_id)})
    if parent is None:
        return   # gateway not registered: stay top-level, never dangle

    own = registry.async_get_device(identifiers={(DOMAIN, self.device.iot_id)})
    if own is None or own.via_device_id == parent.id:
        return   # already linked

    registry.async_update_device(own.id, via_device_id=parent.id)

Three guards keep it safe:

Condition Behaviour
No parent_iot_id Return immediately — standalone devices never touch the registry
Gateway not registered Leave via_device_id unset: a parentless device renders at the top level, whereas a dangling id is dropped silently
Already linked No-op, so repeated setups do not churn the registry

Behaviour change

None for standalone devices. They report an empty parent_iot_id, so the
hook returns before doing any registry work — the branch never executes.

For gated devices the outcome is the same as before (child under gateway), just
through the supported API.

Testing

  • Every module under custom_components/hotata/ parses cleanly
  • via_device= no longer appears anywhere in the tree
  • Deployed against a live HA 2026.9.1 instance: the warning is gone and the
    integration sets up with zero errors

web-flow and others added 3 commits September 14, 2026 00:25
`DeviceInfo.via_device` takes an identifier tuple and is deprecated; Home
Assistant logs a warning on every setup and the parameter stops working in
2027.8:

    Detected that custom integration 'hotata' calls
    `device_registry.async_get_or_create` with a deprecated `via_device`
    parameter; use `via_device_id` instead at custom_components/hotata/entity.py

The replacement cannot be a drop-in swap. `via_device_id` needs the *device
registry id* of the gateway, and that id does not exist while `__init__` runs:
the gateway device may not be registered yet, and entities are constructed
before the registry has processed them.

The link is therefore established in `async_added_to_hass`, after both the
entity's own device and its gateway are in the registry:

* no `parent_iot_id` -> nothing to link, return immediately;
* gateway not in the registry -> leave `via_device_id` unset, which correctly
  renders the device at the top level instead of attaching a dangling id;
* already linked -> no-op, so repeated setups do not churn the registry.

Devices without a gateway (a standalone airer, as this project's own hardware
reports) are unaffected: `parent_iot_id` is empty and the hook returns before
touching the registry.
@C3H3-AI
C3H3-AI merged commit ee3761b into main Sep 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants