Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cover state restoration from the HA entity cache #412

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from

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

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

Additional information

This PR uses #410 as a base

Copy link

codecov bot commented Apr 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.68%. Comparing base (2e8fbe8) to head (11609df).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #412   +/-   ##
=======================================
  Coverage   96.68%   96.68%           
=======================================
  Files          61       61           
  Lines        9834     9845   +11     
=======================================
+ Hits         9508     9519   +11     
  Misses        326      326           

☔ 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
…e HA cache

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

Uses zigpy#410 as a base.
@jeverley jeverley force-pushed the cover-correctly-handle-restore-of-movement-state branch from 1e4e331 to 8b15410 Compare April 9, 2025 13:46
…vice has already reached the movement extrema

- Updates tests to use a common mock cover device creation function to reduce code repetition
@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
- 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
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