$ show RobHofmann/HomeAssistant-GreeClimateComponent
This is a Home Assistant custom component (integration) for controlling Gree-compatible air conditioners over the local network via UDP. It implements the Gree reverse-engineered protocol, supporting two encryption versions (AES-128 ECB and AES-128 GCM), device discovery, key negotiation, and full HVAC control (temperature, fan, swing, modes). The architecture follows Home Assistant's platform pattern: a climate entity as the core, with additional switch, sensor, number, and select entities for auxiliary features like X-Fan, lights, health mode, temperature step, and external temperature sensor selection. The integration communicates directly with the AC unit on UDP port 7000, encrypting commands with device-specific keys obtained during setup. It supports both UI config flow (with auto-discovery and cross-VLAN unicast scanning) and YAML configuration. The codebase is well-structured for a custom component, with clear separation of protocol logic (gree_protocol.py), temperature math (helpers.py), and entity definitions. Notable craftsmanship includes the TempOffsetResolver class for auto-detecting sensor offsets, the retry logic with progressive backoff and diagnostic failure classification, and the use of dataclass-based entity descriptions for switches and sensors. However, the main climate.py file is large (912 lines) and there are no automated tests, which is typical for community Home Assistant integrations.
The LLM identified 3 files worth highlighting for reuse:
Contains the TempOffsetResolver class that auto-detects whether a Gree AC sensor reports raw temperatures or raw+40°C offset by tracking historical min/max and applying a penalty function. Also provides encode_temp_c/decode_temp_c for 0.5°C precision encoding (SetTem/TemRec bits) and gree_f_to_c/gree_c_to_f for Fahrenheit conversion. These functions are self-contained, well-documented, and could be extracted for any project needing similar temperature math or sensor offset detection.
Implements the low-level UDP protocol for Gree devices: AES encryption/decryption (ECB and GCM modes), device discovery via broadcast and unicast, key negotiation, and a FetchResult function with 8 retries and progressive backoff. Includes a _classify_unreachable diagnostic that distinguishes 'port unreachable', 'device responded but encrypted exchange failed', and 'no response' to aid troubleshooting. The discovery logic supports cross-VLAN scanning with CIDR expansion and rate limiting. This module is isolated from Home Assistant specifics and could be reused as a standalone Gree protocol library.
Provides a reusable base entity class (GreeEntity) and a GreeEntityDescription dataclass that standardizes entity creation for switches, sensors, numbers, and selects. The description pattern allows declarative definition of property_key, value_fn, set_fn, available_fn, icon_fn, etc., reducing boilerplate. This pattern is a clean example of the Home Assistant entity description pattern and could be adapted for other integrations.