Skip to content

Conversation

@jeverley
Copy link
Contributor

@jeverley jeverley commented Apr 9, 2025

What's changed

This PR handles edge cases in restoring state after ZHA has been offline.

The current behaviour results in the cover stuck in a restored OPENING/CLOSING state until the device reports a position update (could be up to 5 mins with some devices).
We also currently restore open/closed state regardless of the device's actual position.

The below changes have been made to handle state restoration correctly

  • When restoring CLOSING/OPENING states
    • The function checks if the cover is already CLOSED/completely OPEN (i.e. 100%)
    • The function schedules a call-back to determine the final state after the default timeout period
  • We do not restore CLOSED/OPEN states, instead the state is determined from current position during init

Other improvements

  • The lift/tilt transition and state restore TimerHandles are cancelled upon entity removal

Updates to cover tests

  • Expand state restoration test to handle the different possible scenarios
  • Use a common mock device create function (like the ZHA light platform) to reduce code repetition
  • Add tests for cancelling TimerHandles on removal of the cover entity

@codecov
Copy link

codecov bot commented Apr 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.67%. Comparing base (b1d5b8f) to head (cb7fc93).
Report is 7 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #412   +/-   ##
=======================================
  Coverage   96.67%   96.67%           
=======================================
  Files          61       61           
  Lines        9987     9992    +5     
=======================================
+ Hits         9655     9660    +5     
  Misses        332      332           

☔ 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.

@jeverley jeverley marked this pull request as draft April 9, 2025 09:49
@jeverley jeverley changed the title Refresh cover state after the default timeout when restoring from the HA entity cache Improvements cover state restoration from the HA entity cache Apr 9, 2025
@jeverley jeverley force-pushed the cover-correctly-handle-restore-of-movement-state branch from 1e4e331 to 8b15410 Compare April 9, 2025 13:46
@jeverley jeverley changed the title Improvements cover state restoration from the HA entity cache Improve cover state restoration from the HA entity cache Apr 9, 2025
@puddly puddly force-pushed the cover-correctly-handle-restore-of-movement-state branch from 11609df to 8a251dd Compare April 15, 2025 23:08
@puddly
Copy link
Contributor

puddly commented Apr 15, 2025

I've rebased this PR on top of dev, since there was a conflict with the first cover platform PR now being merged.

@jeverley jeverley marked this pull request as ready for review April 17, 2025 18:20
@jeverley
Copy link
Contributor Author

I've rebased this PR on top of dev, since there was a conflict with the first cover platform PR now being merged.

Thanks @puddly, this one should be ready for review now too.

@jeverley jeverley force-pushed the cover-correctly-handle-restore-of-movement-state branch from a15538a to 765324b Compare April 23, 2025 15:26
…e HA cache

This adds a timeout for movement states restored from the entity cache.

Uses zigpy#410 as a base.
…vice has already reached the movement extrema

- Updates tests to use a common mock cover device creation function to reduce code repetition
- We init `_state` with None and let the `_determine_cover_state` function populate the value from current positions
- Ensures all lines are coverable by tests
@jeverley jeverley force-pushed the cover-correctly-handle-restore-of-movement-state branch from 0d55d6a to 27cda67 Compare April 23, 2025 16:13
@jeverley jeverley force-pushed the cover-correctly-handle-restore-of-movement-state branch 2 times, most recently from f86216b to 1a28055 Compare April 24, 2025 11:03
@jeverley jeverley force-pushed the cover-correctly-handle-restore-of-movement-state branch from fb0abe2 to ff977f0 Compare April 24, 2025 11:11
@jeverley jeverley force-pushed the cover-correctly-handle-restore-of-movement-state branch from 7d7f656 to 28429be Compare April 27, 2025 09:12
@puddly puddly moved this to Backlog in ZHA Apr 28, 2025
@puddly puddly added this to ZHA Apr 28, 2025
@puddly puddly moved this from Backlog to In progress in ZHA Apr 28, 2025
@puddly puddly merged commit 4776858 into zigpy:dev Apr 29, 2025
9 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in ZHA Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants