Skip to content

Fix VRF sub-device discovery: defer + concurrent subList, robust parsing - #507

Open
meirlo wants to merge 1 commit into
RobHofmann:masterfrom
meirlo:feat/vrf-discovery
Open

meirlo wants to merge 1 commit into
RobHofmann:masterfrom
meirlo:feat/vrf-discovery

Conversation

@meirlo

@meirlo meirlo commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Problem

On multi-split (VRF) setups — one WiFi gateway fronting several indoor units — discovery was unreliable:

  • Some units go missing. Sub-device (subList) fetching ran inline inside the UDP receive loop. That query has its own retries/timeouts, so it blocked the loop and consumed the discovery time budget while other devices' broadcast replies were still arriving. Result: intermittently finding e.g. 3 of 4 units.
  • Single-unit gateways were skipped. A device was only treated as a gateway when subCnt > 1, so a gateway reporting exactly one indoor unit was never expanded.
  • subList parsing was brittle. The old code always sent an encrypted pack with the generic key and pushed the reply through FetchResult, which assumes a pack in the response. Several firmwares answer subList with the unit list at the top level (no pack), or with a pack encrypted using the gateway's bound key rather than the generic key.

Changes

  • Collect gateways during the receive loop and fetch their sub-device lists after the loop, concurrently (asyncio.gather). Keeps discovery fast and stops it from dropping other devices' replies.
  • Treat any subCnt > 0 as a gateway.
  • Rewrite get_subunits_list to send subList unencrypted and handle both response shapes: list at the top level, or a pack encrypted with the gateway's bound device key (bind first, then decrypt; v1 ECB and v2 GCM).
  • Add a small self-contained _fetch_subunits_raw helper for the raw UDP exchange, since the response may have no pack to feed through FetchResult.

Scope

gree_protocol.py only. No behaviour change for standalone (non-VRF) devices — they never enter the gateway path.

Related

Part of a small VRF series. Complements #454 (per-unit device_info/unique_id), which makes each discovered sub-unit its own HA device. This PR is what makes all the sub-units reliably get discovered in the first place.

Testing

Tested on my own setup:

  • Gateway: Gree GR-Gcloud VRF WiFi module fronting 4 indoor units (MACs in subMAC@gatewayMAC form).
  • Encryption: v1 (ECB).
  • Home Assistant: current stable release.

Before this change, re-running discovery intermittently returned only 3 of the 4 units. After it, all 4 indoor units are discovered consistently across repeated scans, and the encrypted-pack subList path decodes correctly with the gateway's bound key.

Two problems made multi-split (VRF) gateways discover unreliably:

1. Sub-device (subList) fetching ran inline inside the UDP receive loop.
   The subList query has its own retries/timeouts, so it blocked the loop
   and ate the discovery time budget, causing other devices' broadcast
   replies to be dropped (e.g. finding 3 of 4 units). Gateways are now
   collected during the loop and queried afterwards, concurrently via
   asyncio.gather, keeping discovery fast and complete.

2. A gateway was only treated as such when subCnt > 1, so single-unit
   gateways were missed. Any subCnt > 0 is now handled as a gateway.

get_subunits_list is rewritten to send subList unencrypted and handle both
response shapes seen in the wild: the sub-unit list at the top level, or
wrapped in a pack encrypted with the gateway's bound device key (bind
first, then decrypt). A small self-contained _fetch_subunits_raw helper does
the raw UDP exchange since the response has no pack to feed through
FetchResult.
@meirlo
meirlo marked this pull request as ready for review September 18, 2026 10:53
p-monteiro added a commit to p-monteiro/HomeAssistant-GreeClimateComponent-Rewrite that referenced this pull request Sep 18, 2026
@RobHofmann RobHofmann added help wanted Extra attention is needed to test This issue needs testing labels Sep 20, 2026
@RobHofmann

Copy link
Copy Markdown
Owner

I need some testers with VRF devices for this one!

p-monteiro added a commit to p-monteiro/HomeAssistant-GreeClimateComponent-Rewrite that referenced this pull request Sep 21, 2026
RobHofmann pushed a commit that referenced this pull request Sep 21, 2026
* Add integration code to python analysis so that autocomplete works for the new tools

* Use VRF local discovery as in #507

* Remove unnecessary check for sub_devices lists length

* Prevent one VRF gateway not connecting from breaking full discovery process

Also properly use the discover timeout for getting the subdevices

* Properly assign VRF subunits a name

* Use the retireved key for sub-units

* Reduce time waster discovering-subdevices when errors occur

---------

Co-authored-by: Pedro Monteiro <p-monteiro@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed to test This issue needs testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants