fix: auto-clear stale encryption key after repeated update failures#442
Open
Dzhuneyt wants to merge 1 commit intoRobHofmann:masterfrom
Open
fix: auto-clear stale encryption key after repeated update failures#442Dzhuneyt wants to merge 1 commit intoRobHofmann:masterfrom
Dzhuneyt wants to merge 1 commit intoRobHofmann:masterfrom
Conversation
When the AC rotates its session key (e.g. after Wi-Fi re-pairing via MODE+WIFI on the unit), the integration kept encrypting with the stale cached key forever, leaving the entity Unavailable until a manual reload. Track consecutive update failures; after STALE_KEY_THRESHOLD (default 3), discard the cached key so the existing async_update re-bind path auto-recovers on the next tick. User-configured keys (CONF_ENCRYPTION_KEY) are preserved and only logged — silently overriding a static key the user explicitly set would be surprising. Refs RobHofmann#441
Owner
|
Seems promising. Would be nice if people could help test this one! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #441.
Summary
When a Gree AC rotates its session key (reproduced by putting the unit into Wi-Fi re-pairing mode via MODE + WIFI), the integration kept encrypting requests with the stale cached key forever — the climate entity stayed
Unavailableuntil the user manually reloaded the integration.This patch tracks consecutive update failures and, after a threshold, discards the cached key so the existing
async_updatere-bind path auto-recovers on the next poll tick. User-configured keys are preserved.See #441 for full symptoms, logs, root-cause analysis, and repro steps.
Change
Single-file change (~35 lines added, 0 removed) in
custom_components/gree/climate.py:STALE_KEY_THRESHOLD = 3module-level constant__init__:_user_provided_key = bool(encryption_key)— remembers whether the user supplied a static key at setup_consecutive_update_failures = 0_handle_comms_failure()helper:_encryption_key+CIPHER, logs warning, resets counterSyncStateresets the counter on successfulGreeGetValues, calls_handle_comms_failure()in the existingexceptblocks for bothGreeGetValuesandSendStateToAcNo changes to the happy path — only triggers when comms are already failing.
Why the
_user_provided_keyguardCONF_ENCRYPTION_KEYis an optional user-editable field in the config flow. Users who deliberately set a static key would otherwise see it silently replaced by whateverbindreturns after a transient network blip. With the guard, blank-key setups (the common case, auto-bind) get auto-healing; users who typed a key get a warning but no silent override.Recovery mechanism (no new code path needed)
Existing
async_updatealready re-binds when_encryption_key is None:This PR just triggers that path after repeated failures instead of only at first boot.
Scope
climate.py. Other platforms (switch.py,sensor.py,number.py,select.py) share the climate instance viahass.data[DOMAIN][entry.entry_id]["device"](seeentity.py) — they don't cache their own keys, so no change needed there.Test plan
py_compilepassesSTALE_KEY_THRESHOLD × scan_interval(default 3 × 60s = 3 min) after Wi-Fi re-pairing, no manual reload needed