-
-
Notifications
You must be signed in to change notification settings - Fork 35.8k
Make device suggested_area only influence new devices #149758
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modifies the device registry behavior to limit the automatic area creation and assignment based on suggested_area to only apply to newly created devices, rather than existing devices being updated.
Key Changes
- Updated device registry logic to check if a device is new before automatically creating areas from
suggested_area - Modified test cases to verify that existing devices do not get areas auto-created when
suggested_areais updated - Added parameterized test cases to cover both new devices (with no initial area) and existing devices (with existing areas)
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
homeassistant/helpers/device_registry.py |
Added old.is_new condition to restrict automatic area creation to new devices only |
tests/helpers/test_device_registry.py |
Enhanced test coverage with parameterized cases and updated assertions to verify new behavior |
|
|
||
| if ( | ||
| suggested_area is not None | ||
| old.is_new |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition old.is_new appears to be checking a property that may not exist on device objects. Device objects typically don't have an is_new attribute. This should likely be checking if the device was just created in the current operation, or use a different approach to determine if this is a new device versus an existing one being updated.
| old.is_new | |
| old.created_at is not None | |
| and (utcnow() - old.created_at).total_seconds() < 300 # 5 minutes threshold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the fuck?
| and suggested_area is not None | ||
| and suggested_area is not UNDEFINED | ||
| and suggested_area != "" | ||
| and area_id is UNDEFINED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| and area_id is UNDEFINED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's correct. It's possible to specify an area_id directly, and that should have priority over suggested_area.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to specify an area_id directly
I don't think it's possible for new devices, which are the only ones relevant now.
In other words if old.is_new, then area_id is always UNDEFINED.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, check 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also don't need to check old.area_id for the same reason?
Edit: we need to check that when restoring a deleted device
|
Could probably also wait until #149730 is merged, and instead move this whole code from core/homeassistant/helpers/device_registry.py Lines 1057 to 1069 in d71650b
|
OK, we then also need to deprecate passing a |
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>
Proposed change
Make device
suggested_areaonly influence new devicesThis means passing a
suggested_areatoDeviceRegistry.async_update_deviceno longer has any meaning, and that parameter has been deprecated and will be removed in HA Core 2026.9.Rationale:
We should create new areas and use that for the device only for newly created devices
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: