Repository navigation
vNext: Fix the DHCP step for the sub-units of a gateway - #548
Merged
Merged
Conversation
When Home Assistant sees the DHCP lease of a VRF gateway or a zone controller, the MAC in the lease is the gateway. The configured devices are its sub-units, so looking the lease MAC up in the entry raised KeyError and the flow failed. The MAC of the discovered device is used now. The entry data was also changed in place through a shallow copy, so async_update_entry saw no change and the new IP was never saved. A deep copy fixes that.
RobHofmann
approved these changes
Oct 9, 2026
RobHofmann
left a comment
Owner
There was a problem hiding this comment.
Thanks, this is a clean fix and both causes are right.
What I checked:
- In Home Assistant 2026.10,
async_update_entryonly saves whenentry.data != data. With the old shallow copy, the nested dicts were changed in place, so the comparison saw no change: the new IP was not saved and the entry was not reloaded. The deep copy fixes that. d.macis always a key in the entry, becauseget_entry_matching_mac(d.mac)already matched it.- I ran the real
async_step_dhcpin my fake-device harness against5.0-devand against this PR merged onto the current5.0-devtip. Base: a gateway lease raisesKeyError, and a plain unit with a new IP is not saved and not reloaded. PR: the sub-units of a gateway and a plain unit both get the new IP, with one reload per entry. An unchanged IP causes no update and no reload. - On my dev instance with my test unit, the PR starts clean and polls normally. I could not test a real DHCP lease there.
Two small things for a later PR, not blocking: the TODO: Check if this only returns True if the IP Changed can go now (it does), and copy.deepcopy(entry_match.data) does not need the dict().
RobHofmann
added a commit
that referenced
this pull request
Oct 9, 2026
Lint installed ruff>=0.16.3, so CI picked up Ruff 0.17.0 the day it came out. 0.17 sorts an import with a trailing pragma comment differently, and const.py failed I001 on every push and PR since #547. None of #547, #548 or #549 touched const.py. 0.16.10 and 0.17.0 want opposite forms of that import, so no code passes both. Pin Ruff to an exact version in lint.yml and requirements_dev.txt so a new release cannot break CI again, and apply the 0.17 fix.
Owner
|
Correction to my review: the
Without the |
RobHofmann
added a commit
that referenced
this pull request
Oct 9, 2026
async_update_entry only returns True when the entry data changed. Since #548 copies the entry data deep, a new IP counts as a change, so the open question in the TODO is answered.
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.
Context
This is a bug fix in preparation for Gree zone controller support. I found it while porting the changes I made for my own zone controller (Gree LE60-13/GH) to this project. The zone controller support itself will come in a later PR. Background and the full plan: https://github.com/Twintop/ha-gree-zone-controller/blob/main/upstream/README.md
Symptom
When Home Assistant reports the DHCP lease of a VRF gateway or a zone controller, the DHCP flow fails:
Seen on Home Assistant 2026.10 after a restart, with the 5 sub-units of a zone controller configured.
Cause
async_step_dhcp()scans that IP and gets the sub-units back. It finds the entry with the MAC of each sub-unit (d.mac), but then looks up the device with the lease MAC, which is not in the entry. For a normal unit the two MACs are the same, so this only fails behind a gateway.new_data = dict(entry_match.data)is a shallow copy. The host is changed inside the nested dicts, and those are the same objects as in the entry.async_update_entry()then compares two equal dicts, sees no change, does not save the new IP and does not reload the entry. This part also affects normal units.Change
d.mac. For a normal unit that is the lease MAC, so nothing changes there.copy.deepcopy(), so the entry sees the change and saves it.docs/configuration.md: the automatic IP update also covers the sub-units of a gateway.Testing
pytest: 254 passed, as before.5.0-dev. I ran them without Home Assistant installed, so I compared the findings with the base branch.