Skip to content

feat: Implement sub-device management and discovery features#148

Open
meirlo wants to merge 5 commits into
cmroche:masterfrom
meirlo:master
Open

feat: Implement sub-device management and discovery features#148
meirlo wants to merge 5 commits into
cmroche:masterfrom
meirlo:master

Conversation

@meirlo
Copy link
Copy Markdown

@meirlo meirlo commented Apr 16, 2026

Add gateway sub-device discovery and management

Summary

Adds support for Gree gateway devices that manage multiple sub-devices (e.g., multi-split systems). During discovery, gateways are automatically queried for their sub-devices, which are returned as regular DeviceInfo objects that can be individually controlled.

Changes

Protocol layer (network.py)

  • Added subList command and response types
  • Added create_sublist_message to request sub-device lists from gateways
  • Added handle_sublist_response handler for sub-device list responses
  • Improved response type resolution to handle packets with top-level t field (used by subList responses)

Cipher (cipher.py)

  • Added cipher_type class attribute to CipherBase, CipherV1 ("v1"), and CipherV2 ("v2")
  • Added CipherBase.create(cipher_type) factory method for creating ciphers by type string

Device (device.py)

  • Added get_sub_devices() method to query a gateway for its sub-devices
  • bind() now auto-uses gateway_key and gateway_cipher from DeviceInfo when no explicit key is provided, enabling seamless sub-device binding
  • update_state() now properly awaits the state response using an event, preventing race conditions
  • Hardened current_temperature and version detection against non-numeric property values

Discovery (discovery.py)

  • scan() now automatically queries discovered gateways for their sub-devices
  • Added include_gateways parameter to optionally include gateway devices in results (default: False)
  • Gateways are identified by sub_count > 0 from the subCnt field in scan responses

Device info (deviceinfo.py)

  • Added sub_count, gateway_key, and gateway_cipher fields

Bug fixes

  • Fixed test_mismatch_temrec_farenheit: send.side_effect was set to None instead of the fake handler
  • Fixed test_issue_69: wraps=fake_send() was calling the function immediately instead of passing it as a callback

Tests

Added tests covering:

  • Sub-device list request/response at the protocol level
  • get_sub_devices() success and timeout paths
  • Sub-device binding with explicit and gateway-inherited keys
  • Sub-device state updates
  • Discovery with subCnt parsing, gateway querying, and include_gateways flag

@meirlo
Copy link
Copy Markdown
Author

meirlo commented Apr 16, 2026

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

❌ Patch coverage is 99.13793% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.84%. Comparing base (cff93f8) to head (0b4bfe7).

Files with missing lines Patch % Lines
greeclimate/device.py 98.07% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #148      +/-   ##
==========================================
+ Coverage   95.65%   96.84%   +1.18%     
==========================================
  Files           8        8              
  Lines         760      855      +95     
==========================================
+ Hits          727      828     +101     
+ Misses         33       27       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant