Skip to content

[DNM] Gree Integration rewrite#373

Draft
p-monteiro wants to merge 104 commits intoRobHofmann:masterfrom
p-monteiro:gree-rewrite
Draft

[DNM] Gree Integration rewrite#373
p-monteiro wants to merge 104 commits intoRobHofmann:masterfrom
p-monteiro:gree-rewrite

Conversation

@p-monteiro
Copy link
Copy Markdown
Contributor

@p-monteiro p-monteiro commented Sep 23, 2025

Caution

This PR changes the domain of the integration, so current users will lose their device configs!
The config schema also changed, so verify your YAML if you use it to configure the devices.
This no longer overwrites the official integration.

This PR introduces a rewrite of this integration. The main goal of this was to better align the integration with the Home Assistant (HA) development workflow with two main changes:

  • Completely separate device API code from HA code
  • Align with code style guidelines (mainly Ruff code formatting and full typing)

Breaking changes

  • Major version bump
  • New domain for the integration
  • Configs have a different schema, devices need to be re-added
  • Translations need to be redone (can use the old ones, but need to be migrated to the new template)

Features

  • Device features are now user-configurable (automatic detection removed due to unreliable Gree API)
  • Async device communication via DataUpdateCoordinator
  • GreeDevice abstraction for device logic
  • Auto Encryption support
  • Expose all device sensors as entities
  • Add device fault detection support
  • Add diagnostics download for config entries and devices
  • Add option to set device temperature units (device display)
  • Add RestoreEntity support in ClimateEntity

Improvements

  • Improve config flow with better validation and error handling
  • Allow reconfiguration of config entries (e.g., device IP changes)
  • Allow individual device removal
  • Make entity restore behavior configurable
  • Refactor Gree API to be fully declarative (remove string guessing)
  • Improve API structure and reuse of logic
  • Improve entity creation and organization

Fixes

  • Improve error handling across config flow and entity setup

Known problems:

  • Broken VRF Device Status (needs debugging, could be fixed later)

As you can see, there are a lot of changes, and I understand if this does not go through as is.

- Change config flow to: be multi step and allow setting the device features; allow to reconfigure an entry
- Separate HA and Device API logic: device API is now declarative and handles device behaviour. HA entities expose the device
- Implement a coordinator
- Async device communication
- More error handling
- Move consts around
- Proper error report on config_flow
- Proper translations on config_flow
- Configuration of timeout
- Fetch device info during binding
@p-monteiro
Copy link
Copy Markdown
Contributor Author

@RobHofmann I was adding the temperature step back, but I'm not sure of its utility.
Is there any device that accepts non-integer ºC/ºF?

@domialex
Copy link
Copy Markdown
Contributor

@p-monteiro
The temperature step should not be in the configuration entities anyways, it should be in the climate options. That was a mistake on my part.

@p-monteiro
Copy link
Copy Markdown
Contributor Author

Hi @domialex, that's fine. I'm more interested in the real use case for it. Should it be locked to integers? I don't think any device supports half degrees or even 0.1 steps, as is the lower limit for the current slider...

@p-monteiro
Copy link
Copy Markdown
Contributor Author

@ChillingSilence, Your device doesn't really want to play along with the fetch_device_info() for getting the firmware version, etc.

I allow binding to occur even with an error in fetch info; let's see if the binding fails now.
I also added tests to try fetching with the device key (if it binds successfully) and the generic ones.

Please try again in alpha.81 and provide the log, even if the bind is successful

@ChillingSilence
Copy link
Copy Markdown

@p-monteiro Hope this helps, using 5e3c35f, tried auto-add, then manually adding with IP+MAC, then manually specifying the encryption key on Auto Encryption Version.

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun home-assistant (no readiness notification)
s6-rc: info: service legacy-services successfully started
2026-03-18 15:05:19.951 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration ac_infinity which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2026-03-18 15:05:19.952 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration gree_custom which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2026-03-18 15:05:19.952 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration intesishome which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2026-03-18 15:05:19.953 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2026-03-18 15:07:23.642 DEBUG (MainThread) [custom_components.gree_custom.config_flow] Found broadcast addresses from HA: ['255.255.255.255']
2026-03-18 15:07:23.643 DEBUG (MainThread) [custom_components.gree_custom.aiogree.transport] Sending broadcast to 255.255.255.255:7000
2026-03-18 15:07:23.644 DEBUG (MainThread) [custom_components.gree_custom.aiogree.transport] Waiting 5 seconds for UDP replies... 
2026-03-18 15:07:28.645 DEBUG (MainThread) [custom_components.gree_custom.aiogree.transport] Discovery finished. Got 0 responses
2026-03-18 15:08:04.665 INFO (MainThread) [custom_components.gree_custom.aiogree.device] Initialize the GREE Device API for: 580d0d3474fc (192.168.22.120:7000)
2026-03-18 15:08:04.665 DEBUG (MainThread) [custom_components.gree_custom.aiogree.device] Version: None, Key: [omitted]
2026-03-18 15:08:06.668 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 1/2
2026-03-18 15:08:09.172 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 2/2
2026-03-18 15:08:09.974 ERROR (MainThread) [custom_components.gree_custom.aiogree.device] Could not fetch device info before binding
Traceback (most recent call last):
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 488, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/asyncio_dgram/aio.py", line 124, in recv
    data, addr = await self._recvq.get()
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/queues.py", line 186, in get
    await getter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 45, in udp_request
    received_data, _ = await asyncio.wait_for(recv_task, self.timeout)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 487, in wait_for
    async with timeouts.timeout(timeout):
               ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/timeouts.py", line 114, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 173, in get_result_pack
    recv_json = await transport.request_json(json_data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 83, in request_json
    raw = await self.udp_request(json.dumps(payload).encode("utf-8"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 77, in udp_request
    raise GreeConnectionError(
        f"Failed to communicate with device '{self.ip_addr}:{self.port}' after {self.max_retries} attempts"
    ) from last_error
custom_components.gree_custom.aiogree.errors.GreeConnectionError: Failed to communicate with device '192.168.22.120:7000' after 2 attempts

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/device.py", line 165, in fetch_device_info
    self._raw_info = await gree_get_device_info(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self._transport, cipher or self._cipher
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 514, in gree_get_device_info
    data: dict = await get_result_pack(
                 ^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    )
    ^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 178, in get_result_pack
    raise GreeProtocolError("Error in device response") from err
custom_components.gree_custom.aiogree.errors.GreeProtocolError: Error in device response

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/device.py", line 113, in bind_device
    await self.fetch_device_info()
  File "/config/custom_components/gree_custom/aiogree/device.py", line 170, in fetch_device_info
    raise GreeProtocolError(
        f"Failed fetching device info for {self._ip_addr}"
    ) from e
custom_components.gree_custom.aiogree.errors.GreeProtocolError: Failed fetching device info for 192.168.22.120
2026-03-18 15:08:09.980 INFO (MainThread) [custom_components.gree_custom.aiogree.api] Trying to perform binding. Testing both versions with generic keys
2026-03-18 15:08:09.980 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Requesting bind to device with encryption key v1
2026-03-18 15:08:09.981 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Bind Pack: {'mac': '580d0d3474fc', 't': 'bind', 'uid': 0}
2026-03-18 15:08:09.981 DEBUG (MainThread) [custom_components.gree_custom.aiogree.cipher] Encrypting data (V1): {"mac": "580d0d3474fc", "t": "bind", "uid": 0}
2026-03-18 15:08:09.987 DEBUG (MainThread) [custom_components.gree_custom.aiogree.cipher] Encrypted data (V1): Fo0NJVLzyhX4Qh3bOqWhT4QPXnuPS0a5W/exMkAoHz3IfE1fYVsWM5kifDBw/LN1
2026-03-18 15:08:09.988 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Payload: {'cid': 'app', 'i': 1, 'pack': 'Fo0NJVLzyhX4Qh3bOqWhT4QPXnuPS0a5W/exMkAoHz3IfE1fYVsWM5kifDBw/LN1', 't': 'pack', 'tcid': '580d0d3474fc', 'uid': 0}
2026-03-18 15:08:11.989 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 1/2
2026-03-18 15:08:14.494 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 2/2
2026-03-18 15:08:15.295 ERROR (MainThread) [custom_components.gree_custom.aiogree.api] Error in bind request using encryption key with version 1
Traceback (most recent call last):
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 488, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/asyncio_dgram/aio.py", line 124, in recv
    data, addr = await self._recvq.get()
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/queues.py", line 186, in get
    await getter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 45, in udp_request
    received_data, _ = await asyncio.wait_for(recv_task, self.timeout)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 487, in wait_for
    async with timeouts.timeout(timeout):
               ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/timeouts.py", line 114, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 173, in get_result_pack
    recv_json = await transport.request_json(json_data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 83, in request_json
    raw = await self.udp_request(json.dumps(payload).encode("utf-8"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 77, in udp_request
    raise GreeConnectionError(
        f"Failed to communicate with device '{self.ip_addr}:{self.port}' after {self.max_retries} attempts"
    ) from last_error
custom_components.gree_custom.aiogree.errors.GreeConnectionError: Failed to communicate with device '192.168.22.120:7000' after 2 attempts

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 359, in gree_try_bind
    result = await get_result_pack(json_payload, cipher, transport)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 178, in get_result_pack
    raise GreeProtocolError("Error in device response") from err
custom_components.gree_custom.aiogree.errors.GreeProtocolError: Error in device response
2026-03-18 15:08:15.300 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Requesting bind to device with encryption key v2
2026-03-18 15:08:15.300 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Bind Pack: {'cid': '580d0d3474fc', 'mac': '580d0d3474fc', 't': 'bind', 'uid': 0}
2026-03-18 15:08:15.300 DEBUG (MainThread) [custom_components.gree_custom.aiogree.cipher] Encrypting data (V2): {"cid": "580d0d3474fc", "mac": "580d0d3474fc", "t": "bind", "uid": 0}
2026-03-18 15:08:15.312 DEBUG (MainThread) [custom_components.gree_custom.aiogree.cipher] Encrypted data (V2): Jtod3XIt89Dxs8SHPnkRBJt2vIVBwAvmIgk1XvjRhurELj0L3QVtft+hse+GRsWcl72qEoTtZbgS4JbKYrud0qPFjVyn, tag='qKWestnLPk4VGayIhFfpRg=='
2026-03-18 15:08:15.312 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Payload: {'cid': 'app', 'i': 1, 'pack': 'Jtod3XIt89Dxs8SHPnkRBJt2vIVBwAvmIgk1XvjRhurELj0L3QVtft+hse+GRsWcl72qEoTtZbgS4JbKYrud0qPFjVyn', 't': 'pack', 'tcid': '580d0d3474fc', 'uid': 0, 'tag': 'qKWestnLPk4VGayIhFfpRg=='}
2026-03-18 15:08:17.314 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 1/2
2026-03-18 15:08:19.819 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 2/2
2026-03-18 15:08:20.620 ERROR (MainThread) [custom_components.gree_custom.aiogree.api] Error in bind request using encryption key with version 2
Traceback (most recent call last):
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 488, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/asyncio_dgram/aio.py", line 124, in recv
    data, addr = await self._recvq.get()
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/queues.py", line 186, in get
    await getter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 45, in udp_request
    received_data, _ = await asyncio.wait_for(recv_task, self.timeout)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 487, in wait_for
    async with timeouts.timeout(timeout):
               ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/timeouts.py", line 114, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 173, in get_result_pack
    recv_json = await transport.request_json(json_data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 83, in request_json
    raw = await self.udp_request(json.dumps(payload).encode("utf-8"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 77, in udp_request
    raise GreeConnectionError(
        f"Failed to communicate with device '{self.ip_addr}:{self.port}' after {self.max_retries} attempts"
    ) from last_error
custom_components.gree_custom.aiogree.errors.GreeConnectionError: Failed to communicate with device '192.168.22.120:7000' after 2 attempts

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 359, in gree_try_bind
    result = await get_result_pack(json_payload, cipher, transport)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 178, in get_result_pack
    raise GreeProtocolError("Error in device response") from err
custom_components.gree_custom.aiogree.errors.GreeProtocolError: Error in device response
2026-03-18 15:08:20.626 ERROR (MainThread) [custom_components.gree_custom.config_flow] Error while binding
Traceback (most recent call last):
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 488, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/asyncio_dgram/aio.py", line 124, in recv
    data, addr = await self._recvq.get()
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/queues.py", line 186, in get
    await getter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 45, in udp_request
    received_data, _ = await asyncio.wait_for(recv_task, self.timeout)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 487, in wait_for
    async with timeouts.timeout(timeout):
               ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/timeouts.py", line 114, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 173, in get_result_pack
    recv_json = await transport.request_json(json_data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 83, in request_json
    raw = await self.udp_request(json.dumps(payload).encode("utf-8"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 77, in udp_request
    raise GreeConnectionError(
        f"Failed to communicate with device '{self.ip_addr}:{self.port}' after {self.max_retries} attempts"
    ) from last_error
custom_components.gree_custom.aiogree.errors.GreeConnectionError: Failed to communicate with device '192.168.22.120:7000' after 2 attempts

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 359, in gree_try_bind
    result = await get_result_pack(json_payload, cipher, transport)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 178, in get_result_pack
    raise GreeProtocolError("Error in device response") from err
custom_components.gree_custom.aiogree.errors.GreeProtocolError: Error in device response

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/config_flow.py", line 675, in async_step_manual_add
    self._discovered_subdevices = await self._devices[
                                  ^^^^^^^^^^^^^^^^^^^^
        _main_device.mac_address_sub
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ].bind_device()
    ^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/device.py", line 118, in bind_device
    key, version = await gree_try_bind(
                   ^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
    )
    ^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 400, in gree_try_bind
    raise GreeBindingError(
        f"Binding failed: Unable to obtain valid encryption version and key pair for {mac_addr} at {transport.ip_addr}"
    ) from error
custom_components.gree_custom.aiogree.errors.GreeBindingError: Binding failed: Unable to obtain valid encryption version and key pair for 580d0d3474fc at 192.168.22.120
2026-03-18 15:08:20.628 DEBUG (MainThread) [custom_components.gree_custom.config_flow] Building main schema with previous values: {'host': '192.168.22.120', 'mac': '580d0d3474fc', 'advanced': {'port': 7000, 'encryption_version': 'Auto-Detect', 'encryption_key': '', 'uid': 0, 'disable_available_check': False, 'max_online_attempts': 5, 'timeout': 10}}
2026-03-18 15:08:42.549 INFO (MainThread) [custom_components.gree_custom.aiogree.device] Initialize the GREE Device API for: 580d0d3474fc (192.168.22.120:7000)
2026-03-18 15:08:42.549 DEBUG (MainThread) [custom_components.gree_custom.aiogree.device] Version: None, Key: cJS3J[omitted]
2026-03-18 15:08:44.552 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 1/2
2026-03-18 15:08:47.056 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 2/2
2026-03-18 15:08:47.858 ERROR (MainThread) [custom_components.gree_custom.aiogree.device] Could not fetch device info before binding
Traceback (most recent call last):
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 488, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/asyncio_dgram/aio.py", line 124, in recv
    data, addr = await self._recvq.get()
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/queues.py", line 186, in get
    await getter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 45, in udp_request
    received_data, _ = await asyncio.wait_for(recv_task, self.timeout)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 487, in wait_for
    async with timeouts.timeout(timeout):
               ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/timeouts.py", line 114, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 173, in get_result_pack
    recv_json = await transport.request_json(json_data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 83, in request_json
    raw = await self.udp_request(json.dumps(payload).encode("utf-8"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 77, in udp_request
    raise GreeConnectionError(
        f"Failed to communicate with device '{self.ip_addr}:{self.port}' after {self.max_retries} attempts"
    ) from last_error
custom_components.gree_custom.aiogree.errors.GreeConnectionError: Failed to communicate with device '192.168.22.120:7000' after 2 attempts

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/device.py", line 165, in fetch_device_info
    self._raw_info = await gree_get_device_info(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self._transport, cipher or self._cipher
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 514, in gree_get_device_info
    data: dict = await get_result_pack(
                 ^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    )
    ^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 178, in get_result_pack
    raise GreeProtocolError("Error in device response") from err
custom_components.gree_custom.aiogree.errors.GreeProtocolError: Error in device response

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/device.py", line 113, in bind_device
    await self.fetch_device_info()
  File "/config/custom_components/gree_custom/aiogree/device.py", line 170, in fetch_device_info
    raise GreeProtocolError(
        f"Failed fetching device info for {self._ip_addr}"
    ) from e
custom_components.gree_custom.aiogree.errors.GreeProtocolError: Failed fetching device info for 192.168.22.120
2026-03-18 15:08:47.864 INFO (MainThread) [custom_components.gree_custom.aiogree.api] Trying to perform binding. Prefering provided key (cJS3J[redacted])
2026-03-18 15:08:47.864 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Requesting bind to device with encryption key v1
2026-03-18 15:08:47.864 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Bind Pack: {'mac': '580d0d3474fc', 't': 'bind', 'uid': 0}
2026-03-18 15:08:47.864 DEBUG (MainThread) [custom_components.gree_custom.aiogree.cipher] Encrypting data (V1): {"mac": "580d0d3474fc", "t": "bind", "uid": 0}
2026-03-18 15:08:47.864 DEBUG (MainThread) [custom_components.gree_custom.aiogree.cipher] Encrypted data (V1): Fo0NJVLzyhX4Qh3bOqWhT4QPXnuPS0a5W/exMkAoHz3IfE1fYVsWM5kifDBw/LN1
2026-03-18 15:08:47.864 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Payload: {'cid': 'app', 'i': 1, 'pack': 'Fo0NJVLzyhX4Qh3bOqWhT4QPXnuPS0a5W/exMkAoHz3IfE1fYVsWM5kifDBw/LN1', 't': 'pack', 'tcid': '580d0d3474fc', 'uid': 0}
2026-03-18 15:08:49.866 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 1/2
2026-03-18 15:08:52.369 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 2/2
2026-03-18 15:08:53.171 ERROR (MainThread) [custom_components.gree_custom.aiogree.api] Error in bind request using encryption key with version 1
Traceback (most recent call last):
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 488, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/asyncio_dgram/aio.py", line 124, in recv
    data, addr = await self._recvq.get()
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/queues.py", line 186, in get
    await getter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 45, in udp_request
    received_data, _ = await asyncio.wait_for(recv_task, self.timeout)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 487, in wait_for
    async with timeouts.timeout(timeout):
               ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/timeouts.py", line 114, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 173, in get_result_pack
    recv_json = await transport.request_json(json_data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 83, in request_json
    raw = await self.udp_request(json.dumps(payload).encode("utf-8"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 77, in udp_request
    raise GreeConnectionError(
        f"Failed to communicate with device '{self.ip_addr}:{self.port}' after {self.max_retries} attempts"
    ) from last_error
custom_components.gree_custom.aiogree.errors.GreeConnectionError: Failed to communicate with device '192.168.22.120:7000' after 2 attempts

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 359, in gree_try_bind
    result = await get_result_pack(json_payload, cipher, transport)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 178, in get_result_pack
    raise GreeProtocolError("Error in device response") from err
custom_components.gree_custom.aiogree.errors.GreeProtocolError: Error in device response
2026-03-18 15:08:53.176 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Requesting bind to device with encryption key v2
2026-03-18 15:08:53.176 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Bind Pack: {'cid': '580d0d3474fc', 'mac': '580d0d3474fc', 't': 'bind', 'uid': 0}
2026-03-18 15:08:53.176 DEBUG (MainThread) [custom_components.gree_custom.aiogree.cipher] Encrypting data (V2): {"cid": "580d0d3474fc", "mac": "580d0d3474fc", "t": "bind", "uid": 0}
2026-03-18 15:08:53.177 DEBUG (MainThread) [custom_components.gree_custom.aiogree.cipher] Encrypted data (V2): Jtod3XIt89Dxs8SHPnkRBJt2vIVBwAvmIgk1XvjRhurELj0L3QVtft+hse+GRsWcl72qEoTtZbgS4JbKYrud0qPFjVyn, tag='qKWestnLPk4VGayIhFfpRg=='
2026-03-18 15:08:53.177 DEBUG (MainThread) [custom_components.gree_custom.aiogree.api] Payload: {'cid': 'app', 'i': 1, 'pack': 'Jtod3XIt89Dxs8SHPnkRBJt2vIVBwAvmIgk1XvjRhurELj0L3QVtft+hse+GRsWcl72qEoTtZbgS4JbKYrud0qPFjVyn', 't': 'pack', 'tcid': '580d0d3474fc', 'uid': 0, 'tag': 'qKWestnLPk4VGayIhFfpRg=='}
2026-03-18 15:08:55.180 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 1/2
2026-03-18 15:08:57.684 WARNING (MainThread) [custom_components.gree_custom.aiogree.transport] Error communicating with 192.168.22.120. Attempt 2/2
2026-03-18 15:08:58.485 ERROR (MainThread) [custom_components.gree_custom.aiogree.api] Error in bind request using encryption key with version 2
Traceback (most recent call last):
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 488, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/asyncio_dgram/aio.py", line 124, in recv
    data, addr = await self._recvq.get()
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/queues.py", line 186, in get
    await getter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 45, in udp_request
    received_data, _ = await asyncio.wait_for(recv_task, self.timeout)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 487, in wait_for
    async with timeouts.timeout(timeout):
               ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/timeouts.py", line 114, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 173, in get_result_pack
    recv_json = await transport.request_json(json_data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 83, in request_json
    raw = await self.udp_request(json.dumps(payload).encode("utf-8"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 77, in udp_request
    raise GreeConnectionError(
        f"Failed to communicate with device '{self.ip_addr}:{self.port}' after {self.max_retries} attempts"
    ) from last_error
custom_components.gree_custom.aiogree.errors.GreeConnectionError: Failed to communicate with device '192.168.22.120:7000' after 2 attempts

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 359, in gree_try_bind
    result = await get_result_pack(json_payload, cipher, transport)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 178, in get_result_pack
    raise GreeProtocolError("Error in device response") from err
custom_components.gree_custom.aiogree.errors.GreeProtocolError: Error in device response
2026-03-18 15:08:58.490 ERROR (MainThread) [custom_components.gree_custom.config_flow] Error while binding
Traceback (most recent call last):
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 488, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/asyncio_dgram/aio.py", line 124, in recv
    data, addr = await self._recvq.get()
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/queues.py", line 186, in get
    await getter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 45, in udp_request
    received_data, _ = await asyncio.wait_for(recv_task, self.timeout)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/tasks.py", line 487, in wait_for
    async with timeouts.timeout(timeout):
               ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.14/asyncio/timeouts.py", line 114, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 173, in get_result_pack
    recv_json = await transport.request_json(json_data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 83, in request_json
    raw = await self.udp_request(json.dumps(payload).encode("utf-8"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/transport.py", line 77, in udp_request
    raise GreeConnectionError(
        f"Failed to communicate with device '{self.ip_addr}:{self.port}' after {self.max_retries} attempts"
    ) from last_error
custom_components.gree_custom.aiogree.errors.GreeConnectionError: Failed to communicate with device '192.168.22.120:7000' after 2 attempts

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/aiogree/api.py", line 359, in gree_try_bind
    result = await get_result_pack(json_payload, cipher, transport)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 178, in get_result_pack
    raise GreeProtocolError("Error in device response") from err
custom_components.gree_custom.aiogree.errors.GreeProtocolError: Error in device response

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/gree_custom/config_flow.py", line 675, in async_step_manual_add
    self._discovered_subdevices = await self._devices[
                                  ^^^^^^^^^^^^^^^^^^^^
        _main_device.mac_address_sub
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ].bind_device()
    ^^^^^^^^^^^^^^^
  File "/config/custom_components/gree_custom/aiogree/device.py", line 118, in bind_device
    key, version = await gree_try_bind(
                   ^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
    )
    ^
  File "/config/custom_components/gree_custom/aiogree/api.py", line 400, in gree_try_bind
    raise GreeBindingError(
        f"Binding failed: Unable to obtain valid encryption version and key pair for {mac_addr} at {transport.ip_addr}"
    ) from error
custom_components.gree_custom.aiogree.errors.GreeBindingError: Binding failed: Unable to obtain valid encryption version and key pair for 580d0d3474fc at 192.168.22.120
2026-03-18 15:08:58.491 DEBUG (MainThread) [custom_components.gree_custom.config_flow] Building main schema with previous values: {'host': '192.168.22.120', 'mac': '580d0d3474fc', 'advanced': {'port': 7000, 'encryption_version': 'Auto-Detect', 'encryption_key': 'cJS3JDim581t3914', 'uid': 0, 'disable_available_check': False, 'max_online_attempts': 5, 'timeout': 10}}

@p-monteiro
Copy link
Copy Markdown
Contributor Author

p-monteiro commented Mar 18, 2026

That's some really odd behaviour there @ChillingSilence.
There's definitely something wrong with the connection, either on HA, integration, or the host.

Just so we are on the same page:

  • What is the HA setup? Where is it installed? What's the network configuration?
  • Does the device work correctly on the public version of this integration (https://github.com/RobHofmann/HomeAssistant-GreeClimateComponent/tree/master)? If so, what is the encryption version it is using?
  • Is the device responding to pings ping 192.168.22.120 from both inside the HA container (if applicable) and its host
  • If on a Linux Docker host, what's the output of nc -u -zv 192.168.22.120 7000?

@ChillingSilence
Copy link
Copy Markdown

Home Assistant is an x86_64 HAOS install. The network is a flat 192.168.22.0/24 with an Edgerouter-X giving out DHCP and a Ubiquiti U6-LR. There's no firewall or anything on the LAN, the router is doing NAT only and the WiFi is bridging to the LAN. Other things that use broadcasting are fine, like Chromecast etc

I've just checked now. It seems the device doesn't work on the other public version either.

It responds to pings from within the HA "Terminal & SSH" addon, and also from another workstation on my network.
Netcat shows no output when run either from WSL on the workstation PC or from within HAOS.

It is a relatively new AC purchase / install / unit so I wonder if it's perhaps just a new type? I found this repo originally and this PR seemed to be getting the most love do honestly I started here. Trying the other primary public repo now though and sadly also no joy.

The app shows the following, in case it's helpful:
Screenshot_20260319-101549
Screenshot_20260319-101554

Ran nmap and it showed all TCP ports closed, but it does respond to pings... Confirmed it's the right device too, the arp table matches the DHCP lease which matches the details from luc10/gree-api-client
The details I'm getting returned from the Gree AU server are correct (I'm in New Zealand) and if I try another server (like NA or Russia) the Python script fails, so I'm confident it's being provided the right information back.

@p-monteiro
Copy link
Copy Markdown
Contributor Author

p-monteiro commented Mar 18, 2026

@ChillingSilence ahh, alright. I was under the assumption it was working in the "master" version, and I was actually losing my head, because nothing is functionally different here. So if that is not the case, we shall move to another kind of troubleshooting.

I'm not sure the device information is very useful for Gree. I have the same model ID and version as you. However, my firmware is in the range v1.XX and yours is at v3.XX

Netcat shows no output, correct? Or does it error?

I think I read somewhere that Gree uses MQTT in some units, so maybe newer firmwares dropped the legacy UDP protocol we are using here. I will dig around.

Can you send the complete model of your indoor unit?

@ChillingSilence
Copy link
Copy Markdown

Ahh my apologies @p-monteiro I had only just tried it now with the master version so didn't know it wasn't behaving there otherwise. My bad.

Netcat shows now output, correct. No errors, just, nothing.

I have 2x Gree Kingfisher GWH24ATEXF units. I can confirm they work on the WiFi, and I can disconnect my phone to use 4G and still control them... So they're talking somehow. I wonder if I can packet capture from the router 🤔

@p-monteiro
Copy link
Copy Markdown
Contributor Author

@ChillingSilence, packet capture would be the best way if you actually know how to do it. I'm not good at it.

@ChillingSilence
Copy link
Copy Markdown

It looks like it's still doing stuff on UDP port 7000? All the five packets are pretty much the same
image
The actual commands afterwards from "the cloud" seem to happen on TCP port 1982.

Is this helpful as a starting point thought @p-monteiro ?
Grateful for your assistance, thanks again 🙏

@p-monteiro
Copy link
Copy Markdown
Contributor Author

@ChillingSilence It's performing the normal {"t":"scan"} broadcast. What is the device sending back after those?
src: 192.168.22.120 dst: 192.168.22.86

Also, I would prefer not to pollute this PR with this since it is unrelated to it. Open a new issue, and we can continue discussing there.

@p-monteiro
Copy link
Copy Markdown
Contributor Author

p-monteiro commented Mar 26, 2026

@RobHofmann I'm down to get this merged into a different branch and published as an alpha/beta version. Fixes can then be made against that. I'll let you decide whatever you deem fit for the project. Remember, this is a breaking update.
The only thing I prefer to do extra is to drop yaml config as per HA guidelines (https://github.com/home-assistant/architecture/blob/master/adr/0010-integration-configuration.md#decision), but I understand if you are against it.

Refer to the original PR message (#373 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants