fix(entity): replace deprecated via_device with via_device_id - #9
Merged
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Home Assistant logs a deprecation warning on every setup:
DeviceInfo.via_devicetakes an identifier tuple, which the device registryno 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_idneeds the device registry id of the gateway, and that iddoes not exist when
__init__buildsDeviceInfo: entities are constructedbefore 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'sown device and its gateway are registered:
Three guards keep it safe:
parent_iot_idvia_device_idunset: a parentless device renders at the top level, whereas a dangling id is dropped silentlyBehaviour change
None for standalone devices. They report an empty
parent_iot_id, so thehook 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
custom_components/hotata/parses cleanlyvia_device=no longer appears anywhere in the treeintegration sets up with zero errors