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.