From 47ee6b789a7aac261bd9e4986af1df86f6fecda1 Mon Sep 17 00:00:00 2001 From: Twintop Date: Fri, 9 Oct 2026 20:33:01 +1100 Subject: [PATCH] Fix the DHCP step for the sub-units of a gateway 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. --- custom_components/gree_custom/config_flow.py | 13 ++++++++----- docs/configuration.md | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/custom_components/gree_custom/config_flow.py b/custom_components/gree_custom/config_flow.py index e42d54d..19d1c66 100755 --- a/custom_components/gree_custom/config_flow.py +++ b/custom_components/gree_custom/config_flow.py @@ -1,6 +1,7 @@ """Config flow to configure the Gree integration.""" from collections.abc import Mapping +import copy from ipaddress import IPv4Address, IPv4Network, ip_address, ip_network import logging from typing import TYPE_CHECKING, Any, override @@ -358,11 +359,13 @@ async def async_step_dhcp( discover.remove(d) - # update data - new_data = dict(entry_match.data) - new_data[CONF_DEVICES][discovery_info.macaddress][ - CONF_DEVICE_CONNECTION - ][CONF_DEVICE_CONNECTION_LOCAL][CONF_HOST] = discovery_info.ip + # update data. Behind a gateway the DHCP MAC is the gateway, + # and the configured devices are its sub-units, so use the MAC + # of the discovered device. Copy deep, so the entry sees a change. + new_data = copy.deepcopy(dict(entry_match.data)) + new_data[CONF_DEVICES][d.mac][CONF_DEVICE_CONNECTION][ + CONF_DEVICE_CONNECTION_LOCAL + ][CONF_HOST] = discovery_info.ip # TODO: Check if this only returns True if the IP Changed if ( self.hass.config_entries.async_update_entry( diff --git a/docs/configuration.md b/docs/configuration.md index 6987f8f..355c6b1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -116,7 +116,7 @@ Open the device page and choose **Delete** from the three dot menu. The device i Two mechanisms keep the stored IP address current when a device gets a new one from DHCP: -- Home Assistant reports DHCP leases of Gree devices to the integration. When the MAC matches a configured device, the stored IP is updated and the entry is reloaded. This only updates known devices. It does not start a setup flow for new ones. +- Home Assistant reports DHCP leases of Gree devices to the integration. When the MAC matches a configured device, or a gateway with configured sub-units (VRF, zone controller), the stored IP of those devices is updated and the entry is reloaded. This only updates known devices. It does not start a setup flow for new ones. - When a poll fails, the integration runs a discovery, looks for the device MAC, and retries once with the new IP. Both need the device to be on a network that Home Assistant can reach with a broadcast. Give the device a fixed IP when it is on another VLAN.