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

Implement external state restoration #58

Merged
merged 37 commits into from
Jul 5, 2024

Conversation

puddly
Copy link
Contributor

@puddly puddly commented Jul 1, 2024

A few platforms in ZHA uses instance attributes and complex logic to derive their state, relying on Home Assistant to persist it and restore it after startup:

  • I've exposed necessary information for some platforms (light and cover) for Home Assistant to store this information as extra state attributes, allowing it to be restore properly. I believe this was actually a bug in the past.
  • Other platforms could be converted to use the ZCL attribute cache, such as binary_sensor and lock. These effectively perform operations that change a ZCL attribute so the attribute cache can be used to maintain state.
  • Others rely on directly computing state from other information and unfortunately will have to be directly restored (siren).

In the future, we need to explore a way to store this extra state. I think zigpy can provide a hook. Alternatively, we can invert the storage logic and have ZHA implement a database driver for zigpy.

Copy link

codecov bot commented Jul 1, 2024

Codecov Report

Attention: Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.25%. Comparing base (6794a64) to head (b8d5c57).
Report is 1 commits behind head on dev.

Files Patch % Lines
zha/application/platforms/number/__init__.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #58      +/-   ##
==========================================
+ Coverage   95.00%   95.25%   +0.25%     
==========================================
  Files          61       61              
  Lines        9306     9335      +29     
==========================================
+ Hits         8841     8892      +51     
+ Misses        465      443      -22     

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

@puddly puddly changed the title Persist lighting color mode Implement external state restoration Jul 3, 2024
zha/application/platforms/light/__init__.py Outdated Show resolved Hide resolved
zha/application/platforms/light/__init__.py Outdated Show resolved Hide resolved
zha/application/platforms/light/__init__.py Outdated Show resolved Hide resolved
zha/application/platforms/light/__init__.py Outdated Show resolved Hide resolved
zha/application/platforms/light/__init__.py Outdated Show resolved Hide resolved
@puddly
Copy link
Contributor Author

puddly commented Jul 3, 2024

I've foregone using the ZCL cache and instead just implement restore_external_state_attributes for the required entities. This makes this PR much simpler.

Copy link
Contributor

@TheJulianJES TheJulianJES left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also looks good IMO

@puddly puddly merged commit 8abf678 into zigpy:dev Jul 5, 2024
6 checks passed
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.

3 participants