fix(climate): keep optimistic state until DKN cloud catches up #4
Reference in New Issue
Block a user
Delete Branch "fix/climate-state-revert"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes a bug where Home Assistant's climate UI flips back to the previous setting moments after a successful change (target temperature, HVAC mode, fan, swing). The unit itself and the DKN mobile app reflect the change correctly — only HA reverts.
Root cause
The DKN cloud's REST endpoint (
/api/v1/installations/dknUsa) lags behind the unit's actual state for 5–60s after a write. The previous optimistic-overlay TTL of 2.5s expired before the cloud caught up, so the next coordinator publish (REST poll or socketdevice-datapush) brought in stale values and the UI re-rendered with them.Fix
Two coordinated changes:
OPTIMISTIC_TTL_SECinconst.py) as a safety bound for cloud-propagation lag._optimistic_setnow records the underlying device key + expected device value. A new_reconcile_optimisticruns on every coordinator publish (REST poll + socket push) and clears any overlay whose device key now reports the expected value — i.e. the moment the cloud confirms the write. The TTL caps how long a silently-failed write can hold a wrong value.Also removes the unused
_wait_for_device_valuehelper.Test plan
custom_components.dkncloudna, confirm overlay entries inhass.data[DOMAIN][entry_id]["optimistic"][mac]disappear once the next coordinator publish carries matching device data — not after the 30s TTL.